Can I use capture and html tag inside liquid tag?

CASE 1 - Capture + Render

I want to find out if I can use capture and render together inside liquid tag. For example:

{%- liquid
capture imagefromshema
render 'get_swatch_textures', item: item
endcapture 
-%}

CASE 2 - Liquid Tag + HTML

I want to find out if I can use liquid tag and echo html tag inside it like below. For example:

{% liquid
 for str in blogs_name
  assign word = str | strip | downcase
   unless blog.handle == word
    if blogs[word] != blank
      echo - {{ blogs[word].title }} ({{ blogs[word].articles_count }})

    endif
   endunless
 endfor
%}

CASE 3 - Liquid Tag + Capture + Render + HTML

I want to find out if I can use capture, render and echo html tag inside a liquid tag like below. For example:

{%- liquid
  for i in (1..10)
    assign group_data = 'filtergroup' | append: i
    assign group_key = 'show_' | append: group_data
    assign group_title = 'title_' | append: group_data
    assign tag_lang = ',' | append: settings[group_data] | strip_newlines
    capture value
      render 'get_current_sidebar_filters', key_access: group_key, key_data: group_data
    endcapture
  
    if value != ''
      assign value = value | replace: 'amp;', '' | split: ','
      for d in value
        assign count = count | plus: 1
      if forloop.first
      echo - {{ settings[group_title] }}:

  endif
-%}

CASE 4 - Liquid Tag + Script

I want to find out if I can use echo to print a script inside a liquid tag like below. For example:

{% liquid
if settings != '-' and isAdmin == false
 echo 
 endif
%}

Hi @jetro4u ,

  • 1: This is possible, you just need to get it out( code: {{ imagefromshema }} ), everything will show up fine.

  • 2: You can’t echo html, so this code won’t be able to. echo tag will be similar to the following code:

{{ - {{ blogs[word].title }} ({{ subtotal_new }})
 }}

So you need to remove liquid tag to show it:

{%-  for str in blogs_name -%}
        {%- assign word = str | strip | downcase -%}
         {%- unless blog.handle == word -%}
         {%- if blogs[word] != blank -%}
            - {{ blogs[word].title }} ({{ blogs[word].articles_count }})

         {%- endif -%} 
        {%- endunless -%}
     {%-  endfor -%}

Hope it helps!

@LitCommerce do you know how I can capture text or variables? Example:

capture conditional_text
  if a < b
    {{ text_a }}
  else
    {{ text_b }} and also {{ text_c }}
  endif
endcapture

The double curly braces don’t work of course, but what should I do instead?

Never mind, answered my own question.

capture conditional_text
  if a < b
    echo text_a
  else
    echo text_b | append: " and also " | append: text_c
  endif
endcapture

The append filter is what I was missing before.