0

I have custom HTML code on /collections/products.list that I only want to show up on the Homepage, and two other specific collection pages of my website.

I was wondering if there is some sort of query I can wrap my HTML in to only show it on select pages.

Maybe target each page with {squarespace.page-id}?

EDIT

I was able to do {.equal?:squarespace.page-id:"collection-12345"} but I am trying to figure out how to check against multiple pages.

Community
  • 1
  • 1
bryan
  • 8,879
  • 18
  • 83
  • 166

1 Answers1

0

No, there's no way to test equality against multiple values within a single equal predicate using JSON-T in Squarespace. However, there are a couple alternatives that minimize duplicate code and improve maintainability.


Option 1:

You could use the following (I'm demonstrating how you could use different values [i.e. using urlID instead of page-id], but you don't have to do that):

{.equal? collection.urlId "home"}
  {@|apply mycustomblock.block}

{.or equal? squarespace.page-id "collection-12345"}
  {@|apply mycustomblock.block}

{.or equal? squarespace.page-id "collection-54321"}
  {@|apply mycustomblock.block}

{.or}
  <!-- all the rest -->

{.end}

That's not exactly what you want, but it's more maintainable than, say, nested {.equal}{.or}'s or keeping duplicate code within the .list file.


Option 2:

Or another approach is to add an additional layout via your template.conf file. This will reference the same regions as your other layouts, but will have a distinct region name.

...
"layouts" : {
  "default" : {
    "name" : "Standard Page Layout",
    "regions" : [ "site" ]
  },
  "productsAlt" : {
    "name" : "Products Enhanced",
    "regions" : [ "site" ]
  }
},
...

You'll then get a "Layout" dropdown in the settings panel for collections where you can distinguish between layouts. For the three pages you want to have the alternative products layout, select the alternative layout from the dropdown.

enter image description here

Then, via JSON-T, you can do something like:

{.equal? collection.regionName "productsAlt"}
  <!-- Alt layout. -->
{.or}
  <!-- Std./Non-Alt layout. -->
{.end}

That's not exactly the intended use of "layouts" (typically you'd use them to actually utilize a different set/sequence of region files), but it allows you to have a modifiable, collection-specific property that can then be accessed via server-side JSON-T. Nothing says you have to use different region files, after all.

Brandon
  • 3,572
  • 2
  • 12
  • 27