Highlighted

Tips: Using content blocks to call HTML fragments

Avatar

Avatar

robayzma

Avatar

robayzma

robayzma

07-12-2018

Assumptions:

You know how to create a fragment.

You know how to create content blocks.

Synopsis:

You want to use a fragment, in a template or a delivery. The fragment can change it's content dynamically based on some logic.

As an example we want to create a footer, that can change content based on a customers preferred language.

Steps:

1. Create the fragments you need in Resources-> Content templates & fragments for example you want to create a fragment in German and in English we can call it:
     "footerDE" and "footerEN" and save them

2. Create a Content Block in Resources -> Content Blocks

   Put in this code

<% if(context.profile.preferredLanguage=='de_de')

         {%> <%@include contentModelFragment='footerDE' %><%}

       else

         {%> <%@include contentModelFragment='footerEN' %><%}

%>

Save it with a telling name

3. Create a Delivery and use the content block you created above. You will have code in the source that looks like this:
     <span class="nl-dce-fragment nl-dce-done" id="span154383380419735" data-nl-name="callFooterFragment" data-nl-label="footer multilingual (callFooterFragment)" contenteditable="false">Footer_Multilanguage</span>