Abbreviations via Content Categories?

Options

We have a lot of places in our site where we could use a way to go back and forth between a full state name and its postal or AP stylebook abbreviation. Is there any way to do this in the templating syntax via content categories (or another method)?

Tagged:

Comments

  • Jim,

    The best way to achieve this is when you're creating state categories assign full state name as a label and a 2-letter abbreviation as a name of the category. This will allow you to easily switch between the two by either calling ${label} or ${name} parameter.

    As for the AP stylebook abbreviations, because there is no mathematical pattern, it might be best to use conditonals like this

    <t:if test="name == 'CA'">Calif.</t:if><t:if test="name == 'TX'">Texas</t:if>

  • Thanks, Elizabeth! I went ahead and implemented a full state list. We already have a state list tied to the states in which Civil War battles were fought. That's where it gets hairy...I have the state list in there, and it's easy enough to pull it up using t:data and a t:list. Unfortuantely, that's as far as I can go. Here's what I have.

    state is a property of the "Battlefield" CT backed by the aforementioned related item category consisting only of the states in which battles were fought. all-states is the related item category containing...well...all the states

    <t:data class="categories" name="all-states" parent="/all-states" />

    <t:list id="all-states">

        <t:if test="label == state">

            <p>Yay, match!</p>

        </t:if>

    </t:list>

    It appears that label is never equal to state. I tried both state and state.label in the above code, but neither work. test="label == 'Maryland'" works, but test="state == 'Maryland'" doesn't, and neither does test="state.label == 'Maryland'".

    Additionally, <t:value id="state"></t:value> works just fine, returning "Maryland", so I tried to record that value like so:

    <t:set id="curstate" value="state" />

    That, however, returns this string:

    com.frontleaf.template.ObjectIterator@18eb8b8

    Is this possible?

  • Jim Drey:

    Thanks, Elizabeth! I went ahead and implemented a full state list. We already have a state list tied to the states in which Civil War battles were fought. That's where it gets hairy...I have the state list in there, and it's easy enough to pull it up using t:data and a t:list. Unfortuantely, that's as far as I can go. Here's what I have.

    state is a property of the "Battlefield" CT backed by the aforementioned related item category consisting only of the states in which battles were fought. all-states is the related item category containing...well...all the states

    <t:data class="categories" name="all-states" parent="/all-states" />

    <t:list id="all-states">

        <t:if test="label == state">

            <p>Yay, match!</p>

        </t:if>

    </t:list>

    It appears that label is never equal to state. I tried both state and state.label in the above code, but neither work. test="label == 'Maryland'" works, but test="state == 'Maryland'" doesn't, and neither does test="state.label == 'Maryland'".

    Additionally, <t:value id="state"></t:value> works just fine, returning "Maryland", so I tried to record that value like so:

    <t:set id="curstate" value="state" />

    That, however, returns this string:

    com.frontleaf.template.ObjectIterator@18eb8b8

    Is this possible?

    Jim,

    Apologies for the delay in response. I don't not believe that at some point in time category.label syntax ever worked or was intended to work. The best way to test for category values is to use <t:list id="category"><t:if test="label == 'value'"> or <t:list id="category"><t:if test="name == 'value'">. I know that previously <t:if test="category == 'label-value'"> used to work, I'll check in on that with our development team and if possible have that functionality restored.

    If you want to set the value of the current category to the variable, you must do that through t:list as well.

    Here's a proper way to assign value of the current category to a variable: <t:list id="state"><t:set id="currstate" value="label" /></t:list>

    The best way to think about categories is that the default value is an  array, so for comparison and printing you must get the string value from  an array before you can do anything with it.

    I hope this clarifies things up a bit.

    Elizabeth

Categories