Sign in

Syntax to use quote mark as text in handlebar

  • This topic has 3 replies, 2 voices, and was last updated 7 months, 4 weeks ago by .
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #5609
    shaun2k

    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
    Sularomo

    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
    shaun2k

    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
    shaun2k

    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>

     

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.