Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Advanced Search
  • 1
jasonbarone

How do I comment out large chunks of JSON-T code in my template?

Question

I was wondering if it's possible to comment out large chunks of JSON-T code.


<!-- 
Comments like this appear in the HTML, which is not what I want.
-->

{# Comments like this work great for single lines of text, and don't show up in HTML}

Are there any other methods of hiding JSON-T and HTML template code?

Edited by jasonbarone

  • 🚀Founder at Squarefront, the global community of Squarespace builders.
  • 🎥Documenting the process of building Squarefront on YouTube.
  • 🚗Senior Design Engineer, Design Platform at Uber.
  • 🍕Connect with me on Instagram, Twitter and Linkedin.
  • Need help with Squarespace? I've used the platform for well over 10 years and have helped thousands of businesses, both small and large. Send me an email!

Share this post


Link to post

8 answers to this question

Recommended Posts

  • 0

It looks like the Sqs JSONT parser does not support multi-line comments. According to the project page they are implemented in the Python version of the parser, I have no idea which version Sqs is using, but when tested, it only spits out an error.


{##BEGIN}multiline comment
{##END}

outputs:


<!-- SQUARESPACE_JSONT_ERROR
template: page default
(line/character offsets reference the template source code)
 1: SyntaxError EOF_IN_COMMENT at line 29 character 40: Reached EOF in the middle of a multi-line comment
-->

In theory you could just abuse the {.section} tag:


{.section multilineComment}
   <p>Assuming there's no variable named 'multilineComment',
   this bit of code should never be rendered.</p>
{.end}

Share this post


Link to post
  • 0

Turn on Word Wrap in your text editor and a single-line comment is as good as a multi-line comment. Like so:

{#Integer ege't urna. Praesent rhoncus, lorem nec facilisis ultrices, magna leo pellentesque neque, eu aliquam diam tellus aliquam pede. Vivamus gravida, risus in pellentesque ultricies, urna odio condimentum sem, ege't tempus augue felis non erat. Nam quis lorem semper pede accumsan vestibulum. Vivamus condimentum.}

If you really need a multi-line comment, you simply build your own out of multiple single-line comments, just like you would in an Apache configuration file:

{#Integer ege't urna. Praesent rhoncus, lorem nec facilisis ultrices,}
{#magna leo pellentesque neque, eu aliquam diam tellus aliquam}
{#pede. Vivamus gravida, risus in pellentesque ultricies, urna odio}
{#condimentum sem, ege't tempus augue felis non erat. Nam quis}
{#lorem semper pede accumsan vestibulum. Vivamus condimentum.}

Some text editors have commands that do this automatically for you.

Edited by Sly

Share this post


Link to post
  • 0

Thanks, unfortunately this won't work for commenting out JSON-T. The trouble I ran into is commenting out a block of JSON, not necessary text.


  • 🚀Founder at Squarefront, the global community of Squarespace builders.
  • 🎥Documenting the process of building Squarefront on YouTube.
  • 🚗Senior Design Engineer, Design Platform at Uber.
  • 🍕Connect with me on Instagram, Twitter and Linkedin.
  • Need help with Squarespace? I've used the platform for well over 10 years and have helped thousands of businesses, both small and large. Send me an email!

Share this post


Link to post
  • 0

Hi all.

This works for me:


{##
   <p>This code won't appear.</p>
   <p>Neither will this.</p>
   {website.id} <!--This won't show either.-->
   Nothing in here will render.
##}

EDIT: Squarespace has published the 'comment directive':


{# This is a single line comment}

{##BEGIN}
   This is a longer,
   mulitline comment
{##END}

But this also works for me, as does my initial example:


{##}
   This is a longer,
   mulitline comment
{##}

-Brandon


If this or any other answer helps you out, please give credit where credit is due and Accept and/or Up-Vote that answer. If it didn't help, feel free to inquire further or wait and see what others have to say. Code is provided without any warranty, expressed or implied.

Edited by brandon

If a response helped you out, send a 'Like' 👍 (bottom-right) and/or 'Upvote' vote.jpg.c260784ece77aec852b0e3049c77a607.jpg (top-left)

Share this post


Link to post
  • 0

Great! It's a very informative post forever. If you really need a multi-line comment, you simply build your own out of multiple single-line comments, just like you would in an Apache server. I have found a piece of new information you can read here to get helpful tips and manage work and other projects.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...