We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 727
    • 502 Posts
    I am looking for an easy way for my end user to insert attributed quotes. For example:

    "Your services were great!" - J. Smith, Springfield

    I see that TinyMCE can mark text as using Blockquote, and I am using the CSS from this site:

    http://notes.natbat.net/2006/11/21/inineimagequotes/

    My problem is the attribution. How can I make it as easy as possible for my end user to create these quotes and be consistant? Entering a snippet would be too complicated.

    Is there a plugin that would work a bit like MediaWiki perhaps? Allowing a user to enter something along the lines of?

    {{Your services were great!|J. Smith, Springfield}}


    If the above isn’t possible is it possible to write a plugin to do the above? Any tips on how to start (which pages to look at) and make it efficient?

    thanks, Andy
      • 7923
      • 4,213 Posts
      I’m not aware of such plugins, but yeah, it’s possible to do a plugin for this and attach it to the ondocmanagersave event


        "He can have a lollipop any time he wants to. That's what it means to be a programmer."
        • 10487 MODX Staff
        • 1,535 Posts
        Well, I’m not too sure how MediaWiki handles stuff like this, I don’t really use it that much.

        But, here’s am example plugin - adapted from a plugin I wrote that needed to do something similar - which should get you started. Note that this plugin runs on the OnWebPagePrerender event, which means that the comments would be available in their original format to editors should they need to add/edit the quotes once the page was saved.

        Because it runs during the page parsing process, I’ve used the following format for the quote matching (so it doesn’t clash with chunk parsing): {! Comment | Attribution !}

        Anyway, here’s the code. Feel to modify to your needs:
        /**
        * Plugin: QuoteConvert
        * Author: Garry Nutting
        * Date: 07/07/07
        *
        * Event: OnWebPagePrerender
        */
        
        $e = &$modx->Event;
        
        // Only on this event
        if ($e->name == 'OnWebPagePrerender') {
        	// regular expressions
        	$replace = '/\{\!(.*?)\|(.*?)\!\}/ims';
        	$with = '<blockquote><p class="quote">\1 - <span class="attribution">\2</span></p></blockquote>';
        
        	// do replacement
        	$modx->documentOutput = preg_replace($replace,$with,$modx->documentOutput);
        }
        

        Hope that helps,
        Garry
          Garry Nutting
          Senior Developer
          MODX, LLC

          Email: [email protected]
          Twitter: @garryn
          Web: modx.com
          • 727
          • 502 Posts
          Garry - that’s perfect! One 30 second tweak and it’s what I needed.

          I was thinking before you posted code of creating a plugin called SimpleSnippet that would find tags like:

          {!name:param1:param2!}


          for example. This would be replaced with the output of the ss:name snippet. The snippet would receive the parameters. The quote call would then be:

          {!quote:A great service!:J. Smith, Tucson!}


          What do you think?

          Andy
            • 33372
            • 1,611 Posts
            If you’re going to do that, then why not use the regular snippet format to begin with?

            [[ss? &quote=`Yadda yadda yadda` &attrib=`Seinfeld`]]

            Doesn’t seem any more complex to me, and it has the benefits of being more efficient and not custom code.

            I like Garryn’s plugin for its simplicity, but to make it more complex would be to reinvent the wheel.

            But then that is the beauty of MODx I guess: People can choose to do things in many, many different ways.
              "Things are not what they appear to be; nor are they otherwise." - Buddha

              "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

              Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
              • 727
              • 502 Posts
              Because the syntax of a snippet call is too much for my client - at least my current one. Some snippets require the & after the ? and some don’t - or perhaps that keeps changing between versions of MODx - but I’ve found it to be a guessing game. Sometimes a space is needed between the & and ? and sometimes that doesn’t work. Sometimes snippets only seem to work if they are all on one line (i.e. no spaces anywhere outside the backticks). Other times it works ok with them. This is fine for me but not for my end users. In addition my typical client has never used the backtick - another thing to explain.

              Another problem is that in 0.9.6 copying and pasting snippet calls results in the snippet call being displayed rather than executed. I then have to fiddle with the HTML to get it to work (not sure exactly what - I just change &amp to & and put everything on one line). My idea will work even after cutting and pasting as it avoids problem areas like ampersands. Cutting and pasting is exactly what my end users will do.

              Less problems = less technical support. I’d rather KISS. smiley Call it "snippets for the end user".

              Andy
                • 727
                • 502 Posts