ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

1st party plugin Word Limiter not working with conditionals

September 15, 2011 3:37pm

Subscribe [4]
  • #1 / Sep 15, 2011 3:37pm

    icd2k3

    51 posts

    Maybe I’m just missing something really easy here, but can’t seem to find a solution

    {if summary_word_length}
        {exp:word_limit total="{summary_word_length}"}
    {if:else}
        {exp:word_limit total="75"}
    {/if}
    {body}

    summary_word_length is a custom field where a user can define specifically how many words they want the summary to display - I want it to default to 75 if nothing is entered into that field

    I’ve tried different conditional placement (no if:else, within the total= field itself, etc) but nothing seems to work - if the user doesn’t enter their word limit it just ends up showing the full body text. Any thoughts?

  • #2 / Sep 15, 2011 3:46pm

    wornjacket

    98 posts

    I’ve never tried this but try in the first condition to set {summary_word_length} as an embedded variable and pass it to an embedded template.

    Like this but change the path to be the correct location of the embedded template:

    {if summary_word_length}
        {embed="template-group/.embed_custom_summary" total="{summary_word_length}"}
    {if:else}
        {exp:word_limit total="75"}
    {/if}

    ——-
    then make a new template
    .embed_custom_summary

    and use this code in it:

    {exp:word_limit total="{embed:total}"}
  • #3 / Sep 15, 2011 4:06pm

    LMO

    203 posts

    I tried this and it worked fine:

    {if num}
    
        {exp:word_limit total='{num}'}
    
            {body}
    
        {/exp:word_limit}
    
    {if:else}
    
           {exp:word_limit total='2'}
    
            {body}
    
        {/exp:word_limit}
    
    {/if}
  • #4 / Sep 15, 2011 4:10pm

    icd2k3

    51 posts

    hahah well i feel dumb, that longer method works fine… the problem must be something with just trying to display the tag within the conditional.

    Thanks!

  • #5 / Sep 15, 2011 5:22pm

    Mark Bowen

    12637 posts

    Hi icd2k3,

    Yep you can’t break up tags like that. You have to place the entire tag into the conditionals or it won’t work.

    So this won’t work :

    {if summary_word_length}
        {exp:word_limit total="{summary_word_length}"}
    {if:else}
        {exp:word_limit total="75"}
    {/if}
    
    {body}
    
    {/exp:word_limit}

    but this will :

    {if summary_word_length}
    
    {exp:word_limit total="{summary_word_length}"}
            {body}
    {/exp:word_limit}
    
    {if:else}
    
    {exp:word_limit total="75"}
            {body}
    {/exp:word_limit}
    
    {/if}

    Make sense?

    Thanks,

    Mark

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases