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.

HTML comments in language variables

August 02, 2007 7:55am

Subscribe [1]
  • #1 / Aug 02, 2007 7:55am

    Cocoaholic

    445 posts

    Hi all,

    My question is: How can I get HTML comment tags in language variables to work inside the “User Message Template”?

    ——————————————————

    For those who need the long story…

    I am using AJAX to handle all EE forms on a client’s website.
    The forms are posted using some javascript function (mootools) and the returned html is then parsed to check what feedback should be given to the user.

    - The ‘html’ variable contains the returned html.
    - The ‘updateLog’ function shows the message in a predefined <div> element
    - ‘test’ is a mootools function to check for a substring

    Example:

    function testResponse(html) {
        // check for messages
        if ( html.test("You are now logged in") ) {
            updateLog("You are now logged in.");
        }
        if ( html.test("You are now logged out") ) {
            // done, redirect to login page
            location.href="/login/";
        }
    }

    This works fine but I have to check for the actual text value.
    Having multiple languages it would be better to just check for the variable name.

    So instead of this:

    "mbr_you_are_logged_in" =>
    "You are now logged in.",

    I would like to do this:

    "mbr_you_are_logged_in" =>
    "<!--mbr_you_are_logged_in-->You are now logged in.",

    This way I can just check for “mbr_you_are_logged_in” and regular User Messages will still display fine (for those who have javascript turned off).

    But unfortunately the “User Message Template” converts my HTML comment tag to entities, like this:

    & lt;!--mbr_you_are_logged_in--& gt;You are now logged in.

    EDIT: It seems that the xhtml formatting in the “show_message” function in “core.output.php” is the cause.

    function show_message($data, $xhtml = TRUE)
        {
        ...

    Of course I could set $xhtml to FALSE, but I’m really looking for a non-hack way to do this.
    Any chance there is some extension hook I can use?

    Cheers.

  • #2 / Aug 02, 2007 8:51am

    Cocoaholic

    445 posts

    Ok, looks like I found a solution using the ‘typography_parse_type_end’ hook.

    I will format my language variables like this (using a regex search and replace):

    "mbr_you_are_logged_in" =>
    "<!--MSG mbr_you_are_logged_in MSG-->You are now logged in.",

    After all typography processing I just convert the code back to HTML comments for only those ‘MSG’ variables.

    $str = str_replace('& lt;!--MSG', '<!--', $str);
    $str = str_replace('MSG--& gt;', '-->', $str);
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases