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.

How do I change all &s to &s on output to the screen??

March 02, 2011 8:04am

Subscribe [3]
  • #1 / Mar 02, 2011 8:04am

    Lorna70

    24 posts

    Hi
    I have a metatags channel to allow the user to enter their own metatags via the custom field group form.  However, my html is not validating correctly because if they use the & character is not rewritten as &.  Is their a way of encoding the text entry so all & are changed to &s when written to the page??  My code is as follows:

    {exp:channel:entries channel="meta_tags" limit="1" dynamic="no" disable="categories|member_data|pagination" url_title="{embed:the_url_title}" }
    <title>{title_tag}</title>
    <meta id="description" name="description" content="{meta_description}" />  
    <meta id="keywords" name="keywords" content="{meta_keywords}" /> 
     {/exp:channel:entries}

    Thanks

  • #2 / Mar 02, 2011 8:50am

    ralph.m

    225 posts

    When you say “written to the page”, where do you mean? Into the title tag that appears at the top of the browser? Or in the HTML you see as you view source?

  • #3 / Mar 02, 2011 9:27am

    Design by Front

    106 posts

    Hey Lorna,

    Can you try wrapping the tag you want processed inside the {exp:xml_encode} tag pair? e.g:

    {exp:xml_encode}
    {title}
    {/exp:xml_encode}

    That should convert any special characters (’&’) into html entities (’&amp;’) and fix your validation issues

    Hope this helps,
    Chuck

  • #4 / Mar 02, 2011 10:55am

    Lorna70

    24 posts

    Excellent thanks Chuck - that worked 😊

  • #5 / Mar 02, 2011 12:04pm

    Design by Front

    106 posts

    No problem, glad to be of help 😊

  • #6 / Mar 02, 2011 3:46pm

    Ingmar

    29245 posts

    Glad to see that helped. Please post again as needed.

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

ExpressionEngine News!

#eecms, #events, #releases