We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14568
    • 14 Posts
    So, on the site I have two types of post a link list item and an article item. For the front page of the site I need to use 2 different templates for the getResources call, one for the linked list and one for articles.

    Articles have a unique templateVariable. At the moment I am using the If snippet to check for the templateVariable in the articles page.

    The big problem I have is that all templateVariables have to be called in the chunk before the IF snippet, this adds a lot of extra junk onto the page.

    Does anyone have a better way of doing this so I don't have to call all these TVs before?

    If you're not to sure, the URL is johnnye.net and check the source.

    The snippet I need improving is:

    <!--[[+pagetitle]][[+id]][[+content]][[+publishedon:strtotime:date=`%a, %d %B %Y`]][[+tv.articleStyle]][[+tv.linkURL]]-->
    [[!If? &subject=`[[+tv.articleStyle]]` 
    &operator=`notempty` 
    &then=`<div class="clear"></div><hr><a href="[[~[[+id]]]]"><h1>[[+pagetitle]]</h1></a>
    <p class="date">Published on: [[+publishedon:strtotime:date=`%a, %d %B %Y`]]</p>
    <div class="[[+tv.articleStyle]]">
      [[+content]]
    </div><hr>` 
    &else=`
    <div class="link-item">
      <a href="[[+tv.linkURL]]"><h2>[[+pagetitle]]</h2></a>
      [[+content]]
    </div>`
    ]]
    

      • 33968
      • 863 Posts
      Does this work:
      [[+tv.articleStyle:notempty=`
          <div class="clear"></div><hr><a href="[[~[[+id]]]]"><h1>[[+pagetitle]]</h1></a>
          <p class="date">Published on: [[+publishedon:strtotime:date=`%a, %d %B %Y`]]</p>
          <div class="[[+tv.articleStyle]]">
            [[+content]]
          </div><hr>
      `:else=`
          <div class="link-item">
            <a href="[[+tv.linkURL]]"><h2>[[+pagetitle]]</h2></a>
            [[+content]] 
          </div>
      `]]
      


      However a custom snippet would be a lot more efficient here wink
        • 14568
        • 14 Posts
        Hi Lucas,
        Thanks for that, yeah it works for of, for me the `:else=` is throwing errors so I replaced it with a conditional on the linkURL template variable.

        Interestingly though, by using the template variable conditional the page load time increases from 0.03 (by using If snippet) seconds to 0.3 seconds(after a page reload to account for caching). This is a similar time if I only have one conditional notempty in the chunk and no else.

        Yes, I should bit the bullet and bash out a custom snippet, as hopefully that will be as quick as the if chunk and much tidier.

        Once again thank for the help.

        -john