Download
We're evolving to serve you better! This current forum has transitioned to read-only mode. For new discussions, support, and engagement, we've moved to GitHub Discussions.

Syntax to use quote mark as text in handlebar

  • #5609
    Avatar photo[anonymous]

    Hi,

    I’m trying to use #getPosts to show posts in a specific order following the example in https://getpublii.com/dev/getposts-helper/#getposts-helper.

    This works:

    {{#getPosts "3,1,2" "<section>" "</section>"}}

    But if I need to assign class name to the <section>, the quote marks for the class name would result in parse error during rendering process.

    {{#getPosts "3,1,2" "<section class="posts">" "</section>"}}

    How can the quote marks be escaped in such a case?

    Thanks.

    
    
    		
    	
    #5612
    Avatar photo[anonymous]

    Can they not be escaped with \” ?  I always thought that was how you’d do it.  If not, how about mixing single quotes in there?  Or referencing a variable with that escaped string?  Or writing an inline helper like the guide suggests?  Or even omit the quotes for now?

    I’m just throwing stuff at you since nobody replied, haha.  Don’t take it as I know what I’m talking about.

    #5613
    Avatar photo[anonymous]

    Thanks for your help @Sularomo.

    I’ve managed to get the code working and in the process found three ways to get around the parsing error.

    Hope this helps those others are also looking at ways to show selected posts in a specific order.  This can be used when the “ordering” and “orderby” criteria in the other “#get” helpers can’t achieve.

    The next thing I hope to figure out how to select the posts I need in sequence from a list rather than hardcoding the string of post IDs.

    <!-- Method 1 - Replacing the double quotes with single quotes -->
    {{#getPosts "3,1,2" "<section class='posts'>" "</section>"}}
    
    <!-- Method 2 - Escaping the double quotes with \" -->
    {{#getPosts "3,1,2" "<section class=\"posts\">" "</section>"}}
    
    <!-- Method 3 - Taking out the HTML prefix and HTML suffix and place them outside the #getPosts helper -->
    <section class=\"posts\">
       {{#getPosts "3,1,2" "" ""}}
       ...
       {{/getPosts}}
    </section>
    #5614
    Avatar photo[anonymous]

    Just realised that I forgot to remove the back-slash from Method 3

    <!-- Method 3 - Taking out the HTML prefix and HTML suffix and place them outside the #getPosts helper -->
    <section class="posts">
       {{#getPosts "3,1,2" "" ""}}
       ...
       {{/getPosts}}
    </section>