Can I insert specific buttons based on labels and have a fallback



Publicado 16 de fev. de 2023

Hi Zendesk Community! 

I am working on inserting buttons on all pages of our help center at the bottom of the page. It seems to be most viable to do this in scripting language. BUT I can came across a challenge with having a fallback button, if the labels do not meet the requirements. 

Logic I want to achieve is: 

  1. Loop through labels 
  2. Check for specific values
  3. Insert buttons based on these values 
  4. If the label of the article does not meet that, insert a fallback button. 

I have the 3 first steps working fine, I just can't figure out a way to achieve a fallback so I can ensure a button on all article pages. 

The short version: Any advice on how I can add a single fallback button based on article labels?

See my code for reference: 

   
      <!--Dynamically add buttons based on labels that link to commercial sites-->
      {{#if article.labels}}
        {{#each article.labels}}
              {{#is identifier 'dtc_forside'}}
                <div style="text-align:center">
                <button type="button" onClick="javascript:window.open('#', '_blank');" class="dtcbutton">TEXT</button>
                </div>
              {{/is}}
              {{#is identifier 'dtc_checkout'}}
                <div style="text-align:center">
                <button type="button" onClick="javascript:window.open('#', '_blank');" class="dtcbutton">TEXT</button>
                </div>
              {{/is}}
              {{#is identifier 'dtc_mittv2'}}
                <div style="text-align:center">
                <button type="button" onClick="javascript:window.open('#', '_blank');" class="dtcbutton">TEXT</button>
                </div>
             {{/is}}
        {{/each}}
    {{/if}}

0

2

2 comentários

Hi Pulkit Pandey

Thank you, this is what I was looking for :) 

0


Hi Søren Dahl Poulsen

Please, replace the below code with your current one and it will help you to add a fallback button.

  <!--Dynamically add buttons based on labels that link to commercial sites-->
      {{#if article.labels}}
        {{#each article.labels}}
              {{#is identifier 'dtc_forside'}}
                <div style="text-align:center">
                <button type="button" onClick="javascript:window.open('#', '_blank');" class="dtcbutton">TEXT</button>
                </div>
              {{/is}}
              {{#is identifier 'dtc_checkout'}}
                <div style="text-align:center">
                <button type="button" onClick="javascript:window.open('#', '_blank');" class="dtcbutton">TEXT</button>
                </div>
              {{/is}}
              {{#is identifier 'dtc_mittv2'}}
                <div style="text-align:center">
                <button type="button" onClick="javascript:window.open('#', '_blank');" class="dtcbutton">TEXT</button>
                </div>
             {{/is}}
        {{/each}}
{{else}}
  <div style="text-align:center">
            <button type="button" onClick="javascript:window.open('#', '_blank');" class="dtcbutton">Alt TEXT</button>
          </div>
    {{/if}}

Let me know if it solves your issue 

 

Thank You 

Pulkit

Team Diziana

0


Entrar para comentar.

Não encontrou o que estava procurando?

Nova publicação