5

I have a link in my Razor template in one of these forms:

<a href="@item.link" target="_blank">@item.link_title</a>

<a href="@item.tridion_pdf" target="_blank">@item.link_title</a>

So the link & title are coming from content. item.link is just a text field to an external URL & tridion_pdf is a link to a PDF stored in Tridion. I want the user to be able to edit the link & title in Experience Manager (XPM). Is this possible? I've Experience Manager enabled images & text fields individually but not any quite like this where the fields I want to edit are within the same HTML tag structure

Any suggestions?

UPDATE:

I think I need a clarification. This question is specifically about rendering the appropriate markup needed to enable fields for use in XPM. If, for example, I just had a simple text field in a div, I could use the following:

<div>@RenderComponentField("title", 0)</div>

That generates markup like the following, which is fine for that field.

<span><!-- Start Component Presentation: {"ComponentID" : "tcm:99-9999", "ComponentModified" : "2013-05-09T13:06:27", "ComponentTemplateID" : "tcm:99-99999-32", "ComponentTemplateModified" : "2013-05-06T13:48:54", "IsRepositoryPublished" : false } -->
    <span><!-- Start Component Field: {"XPath":"tcm:Content/custom:Content/custom:title[1]"} -->
        Sample Title
    </span>
</span>

But if you look at my sample Razor-encoded links, I have 2 fields I want to edit, not just one. So what do I do here?

<a href="@item.link" target="_blank">@item.link_title</a>
  • Thanks for the clarification. This doesn't so much seem to me, now, as a Razor question as it would be an Experience Manager question. The way that you grab the field and output it to HTML won't be any different - but your question isn't really about outputting content from a field. It's that, within experience manager, you want two fields to be editable rather than one - and one of those fields is an attribute on an HTML element while the other is visible text. Is that an accurate summary of the question? – paceaux May 13 '13 at 20:10
  • Yes, that is my question. I want to edit 2 fields that are in the same HTML Element. One is text, the other is an attribute. Want I to do is allow the users to edit the links. Possible? Or Not? – Mr Smith May 13 '13 at 21:09
4

is @item a field in your component?

Also, is this a TBB that's being executed in a CT for a component?

Typically, if you're trying to access fields in a component, you want to tell that to razor by using @Fields

@Fields.link

You can also be more explicit by designating the the object:

@Component.Fields.link

Therefore, I'd think that this is what you want:

<a href="@Fields.tridion_pdf" target="_blank">@Fields.link_title</a>

I haven't used Razor in Experience Manager, but this is how I use Razor for good ol' fashioned page templates and component templates.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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