We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27330
    • 884 Posts
    As the title says, when using this in tpl the output is mixed up if I have <span> in the page title.
    Is this expected or any workaround?

    <h2><a href="[[~[[+id]]]]" title="">[[+pagetitle]]</a></h2>

      • 6228
      • 249 Posts
      Putting html tags in your page title?

      You could try
      <h2><a href="[[~[[+id]]]]" title="">[[+pagetitle:htmlent]]</a></h2>

      Although I suspect it would cause the html tags to display in the output.
        lo9on.com

        MODx Evolution/Revolution | Remote Desktop Training | Development
        • 12241
        • 80 Posts
        would there be a way to convert them back using html_entity_decode as a custom output modifier?
          Environment:
          modx: rev 2.0.8-pl
          localhost: Apache/2.0.63 (Unix) PHP/5.2.11 DAV/2, MySQL client version: 5.1.37
          • 27330
          • 884 Posts
          Quote from: cyclissmo at Mar 05, 2011, 03:43 PM

          Putting html tags in your page title?
          yeah I have some multi colors thingy going on I wanted each pagetitle to have a different color
          for the second word.
          I Thought Jquery/mootools will come to the rescue neatly but couldn’t find anything close enough to play with.
          Ended up using images for that getResource call but I’m not too happy with it.

          anyhow :htmlent will just output
          <span>blahblah</span>
            • 3749
            • 24,544 Posts
            How about taking the <span> tags out of the page titles, putting something like this in your template and doing it with CSS?

            <span id="[[*pagetitle]]">[[*pagetitle]]</span>


            CSS:

            span#MyPage {
            
             color:red;
            
            }
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 27330
              • 884 Posts
              Thanks Bob that’s the way I would try usually but i need the span to get something like this, in txt smiley


                • 33968
                • 863 Posts
                I’ve done something similar with a custom output filter. The filter will append a <span> to the first word in your heading. I hate having html tags where clients can see them!

                When you call your pagetitle, add the filter like this:
                [[*pagetitle:append_span]]


                Then create a new snippet called append_span, containing the following code:

                <?php
                 
                  $space_pos = strpos($input,' ');
                  $before = '<span style="color: red;">';
                  $after = '</span>';
                
                  if($space_pos) 
                  {
                    $title = $before.$input; 
                    $title = substr_replace($title,$after.' ',$space_pos+strlen($before),1); 
                  }
                
                  else $title = $before.$input.$after;
                  
                  return $title;

                ​
                The solution was inspired by this blog post, it seems to work well but no guarantees!
                  • 12241
                  • 80 Posts
                  $space_pos = strpos($input,' ');

                  Is it possible to have a special character be a marker for where the span tags get placed???

                  For example, if I type a title like this: My Cool *Web Page*
                  The output modifier create this: My Cool <span>Web Page</span>

                  This would be perfect for the client to understand and would allow for greater control and multiple words contained in one span.



                    Environment:
                    modx: rev 2.0.8-pl
                    localhost: Apache/2.0.63 (Unix) PHP/5.2.11 DAV/2, MySQL client version: 5.1.37
                    • 12241
                    • 80 Posts
                    I’m not sure what to call it... but I’ve created the output modifier based on the above concept. It works on placeholders in my template but I haven’t yet tested it on a placeholder in a snippet template such as getResources.

                    Usage: To wrap a portion of your page title (or another place holder) in span tags use (*) asterisks to mark the beginning and end.

                    Resource Page Title: This is *my cool page title*

                    Final Output: This is my cool page title

                    Template:
                    [[*pagetitle:append_span]]


                    Snippet:
                    <?php
                    $pattern = '/\*(\b.*?)\*/';
                      $replacement = '$1';  
                      $before = '<span style="color: red;">';
                      $after = '</span>';
                      
                      $title = preg_replace($pattern,$before . $replacement . $after, $input);
                      
                      return $title;
                    
                    
                    
                    


                    Wow, I just realized how cool output modifiers are smiley
                      Environment:
                      modx: rev 2.0.8-pl
                      localhost: Apache/2.0.63 (Unix) PHP/5.2.11 DAV/2, MySQL client version: 5.1.37
                      • 33968
                      • 863 Posts
                      Wow, very nice smiley Surely I’m not the only one who wants to dance around when I get something like this to work?!!

                      Your version gives a lot more control to the end user on how to apply the formatting - I guess it depends how much control you want to give the client/end user. Personally I would rather have them do as little as possible, even if it is a matter of just adding a couple of ’*’s. If the rule is to have the first word coloured, then why not leave it to the system to handle it?

                      I would also suggest applying a class to the span rather than styling it inline within the snippet, so you can keep the css in an external stylesheet.

                      And - yeah, output modifiers are amazing. They allow you to keep all the formatting rubbish out of the database, leaving you with just the raw data to manipulate however you want. Really useful stuff!