We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39159
    • 23 Posts
    I have tried searching for this, but I'm really unsure what I would use as a query to find the answer on these forums, so please forgive me if I've missed something. My question is as follows.

    I am including the introtext from content in my template. I want to format this text, specifically I want to apply a span tag to the first letter. This styling gives me a really large first letter, and the rest of the font regular text. So far I have this.

    [[*introtext:limit=`1`]]
    


    In between the span tags on my template. The rest of this is where I'm getting hung up. I want to have the rest of the introtext follow that immediately, HOWEVER, I want it to be introtext minus the first letter (since I've already inserted/made it huge). Basically

     [[introtext:-firstletter]]
    



    If I could code colloquially smiley Is there any way to do this??? I'm fairly new so if you can be specific with what I should look at, it would be appreciated.
      • 4172
      • 5,888 Posts
      create a new snippet (substring):

      $options=explode(',',$options);
      return count($options)>1 ? substr($input,$options[0],$options[1]) : substr($input,$options[0]);
      


      and use it this way:

      <span>[[*introtext:substring=`0,1`]]</span>[[*introtext:substring=`1`]]


      just added this here:
      http://rtfm.modx.com/display/revolution20/Custom+Output+Filter+Examples#CustomOutputFilterExamples-substring
      [ed. note: Bruno17 last edited this post 14 years, 7 months ago.]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 3749
        • 24,544 Posts
        Very nice.

        Being a speed freak, I would be inclined to do it with a single snippet call and no output modifiers:

        [[!MyIntroText]]


        <?php
        /* MyIntroText snippet */
        
        $txt = $modx->resource->get('introtext');
        
        return '<span class="FirstLetter">' . substr($txt, 0, 1) . '</span>' . substr($txt, 1);



        You could also make it more generic (so it could be used with other fields, (e.g., description or content):

        [[!FirstLetter? &field=`introtext`]]



        <?php
        /* FirstLetter snippet */
        
        $txt = $modx->resource->get($scriptProperties['field']);
        
        return '<span class="FirstLetter">' . substr($txt, 0, 1) . '</span>' . substr($txt, 1);



        ---------------------------------------------------------------------------------------------------------------
        PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
        MODX info for everyone: http://bobsguides.com/modx.html

          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
          • 39159
          • 23 Posts
          Hey guys,

          Thanks for helping out a noob here. I'm really surprised how supportive the forums are here... was on a drupal forum (when I still used that clunker) asking for something similar and I got nothing as quick or too the point. You guys definitely solved my problem that my 2 hours of research sure couldn't ;-)

          Muchly appreciated

          Greg
            • 3749
            • 24,544 Posts
            Welcome to MODX. smiley


            ---------------------------------------------------------------------------------------------------------------
            PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
            MODX info for everyone: http://bobsguides.com/modx.html
              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