2

I'm using DD4T 2 (.NET) with our web app. In SDL Web 8.5, I've got a Component with a rich text field. I add a hyperlink as a Component, using a standard External Link Component and this renders:

<a href="tcm:13-396" target="_blank">sample text</a>

This is expected. I publish the Page and verified that the broker database has the published Page content including the markup shown above.

In the web app, I used DD4T's GetPage(pageId) method to get the Page content and I verify that the Component Presentation still has the markup as expected.

The model:

[ContentModel("general_content", true)]
public class GeneralContent : ViewModelBase
{
    [RichTextField(FieldName = "body_text")]
    public MvcHtmlString BodyText { get; set; }
}

The ComponentPresentationController's action method:

public ActionResult GeneralContent(IComponentPresentation componentPresentation)
{
    var model = ViewModelFactory.BuildViewModel<GeneralContent>(componentPresentation);
    return View(model);
}

Once the Component Presentation is passed to the action method, if I check the model's BodyText property, it seem to have stripped the anchor markup. Just a plain text "... sample text" instead of "... <a href="http://google.co.uk" target="_blank">sample text</a>".

What I've tried:

  • Replaced the external link Component in the rich text field with a basic hyperlink and this link renders as expected.
  • Verify that the TCM URI returns the correct Component
  • Increase link level to 3
  • Verify that markup is included in broker db
  • Verify that markup is retrieved from broker db
  • Had a look at the RichTextField attribute from DD4T.MVC and the DefaultRichTextResolver.cs from DD4T.Core to provide a clue as to why

Is there anything else that I may be missing? Any assistance would be much appreciated.

Update

To clarify, the "External Link Component" I mentioned meant that I created a Component using a schema I created called "External Link".

The two levels I mentioned meant that Component A was linked to Component B and Component B was added to a Page and published. I was attempting to resolve Component A which wasn't on a Page.

6
  • 2
    Can you confirm the Component (tcm:13-396) you are linking to, is actually on a Page and that Page is published? From what I gather, it soulds like you are simply seeing a resolved link, to an unpublished item. Jun 8, 2017 at 14:52
  • Sure, the Component (tcm:13-396) is an External Link which is attached to a Component, which is on a published Page.
    – Tim Alonso
    Jun 8, 2017 at 15:00
  • Sorry, I've misunderstood your earlier statement. Yeah, I can now see why this component will not be resolved as it's two levels away. I may be overthinking my approach and will rethink. Thanks for your response.
    – Tim Alonso
    Jun 8, 2017 at 15:39
  • Might I suggest you edit your question and supply a bit more detail in there explaining what those two levels are exactly. I'm also struggling with your terminology of "External Link Component", I'm not sure what you mean by that? Sometimes screenshots help. Jun 9, 2017 at 8:28
  • 1
    Please edit your question and add this information there, the comments are too small and nobody reads them. Jun 9, 2017 at 10:36

1 Answer 1

0

The root cause was that the Component that I was intending to resolve wasn't on a published Page.

My approach was wrong. I've stopped using the External Link Component and simply used the plain hyperlink text and that worked as expected.

Your Answer

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

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