7

Does anyone have a sneaky way of having tridion resolve component links within a form action?

For example:

<form action="@@Component.ID@@">

Ideally based on standard tridion format href and image tags, I should be able to do:

<form tridion:action="@@Component.ID@@">

My question is really so see if there's a work around to save myself a little time, if there isn't one in the community i'll write and post it here :)

Thanks in advance

3 Answers 3

8

In a Java-based app that takes advantage of Dynamic Component Linking you can do this:

<%@ page import="com.tridion.linking.ComponentLink, com.tridion.linking.Link" %>
<%
    string componentUri = "@@Component.ID@@";
    ComponentLink componentLink = new ComponentLink("@@PublicationUri@@");
    String formActionUrl = componentLink.getLink(componentUri).getURL();
%>

<form action="<%=formActionUrl%>">

TBB to put PublicationUri onto package (assuming you're using TemplateBase):

using Tridion.ContentManager.Templating;
using Tridion.ContentManager.Templating.Assembly;
using Tridion.Extensions.ContentManager.Templating;

namespace ContentBloom.Tridion.Templating
{

    [TcmTemplateTitle("Add Publication Uri")]
    public class AddPublicationUri : TemplateBase
    {
        public override void Transform(Engine engine, Package package)
        {
            Initialize(engine, package);
            string pubUri = this.GetPublication().ToString();

            package.PushItem("PublicationUri", package.CreateStringItem(ContentType.Text, pubUri));
        }
    }
}
3

Have you tried

<form action="dummy.path" tridion:href="tcm:6-543" tridion:type="Multimedia" 
  tridion:targetattribute="action">...

OOOOPS: Now I think about it, that won't really work because it need to respolve at request time...

2
  • If request time resolving wasn't needed, does code this actually work? Quite slick if it does. +1 Commented Jun 4, 2013 at 22:28
  • It works if the component is multimedia, since that URL is resolved at publish time.
    – Nuno Linhares
    Commented Jun 4, 2013 at 23:11
1

You want the URL attribute of a dynamic link in there - I don't think it can be done "OOTB". Rather easy to do on the delivery side, but on the CM not really, since link resolving will always assume you want an anchor tag.

At best you'll end up with something like this:

<form action="<a href="/someurl.jsp">text</a>">

Unless your component is a multimedia component, there is no easy way to do this on the CM side.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.