We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40395
    • 67 Posts
    Hi,

    I'm trying to implement a simple FAQ script that I've used on a couple of sites but am struggling to get the URL's to format correctly in modx. The idea is that the 'questions' link to an anchor on the same page, however the link is not formatting correctly.

    The original elements of code are below:

    while ($row<$numrows){
    	echo($qparastart."<a href=\"#".$faq[$row][$IDindex]."\">".$faq[$row][$qindex]."</a></p>");
    	$row++;
    }
    


    and

    	echo($astart.$faq[$row][$aindex]."<a name=\"".($row+1)."\"></a>".$rowend);
    


    In the first instance I've tried to use the page reference to format the URL correctly which almost works -

    echo($qparastart."<a href=[~71~]\"#".$faq[$row][$IDindex]."\">".$faq[$row][$qindex]."</a></p>");
    


    but the output link is formatted incorrectly:

    http://www.mcpy.co.uk/faq.html"#16"

    (actually coded - http://www.mcpy.co.uk/faq.html%22#16%22 )

    where the anchor has double quotes.

    Any suggestions appreciated.

    Cheers


    David



    [ed. note: alchemy last edited this post 14 years, 2 months ago.]
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      In the first place, you should not use echo statements in snippets. You should gather the output into a variable, such as $output, then finally return the $output.

      In the second place, it's a good idea to use single quotes for the PHP, and double quotes for the HTML so that you don't get them mixed up.

      And you can't use MODx tags inside snippet code; that's PHP and PHP doesn't understand snippet code.

      $output .= $qparastart . '<a href="' . $modx->makeUrl(71) . '#' . $faq[$row][$IDindex] .'">'.$faq[$row][$qindex].'</a></p>');


      Personally, I prefer to use Jot as the FAQ engine, with the "subject" being the question and the "comment" being the answer, and use an output tpl to create the HTML structure for the output. A bit of Jquery can turn a number of different structures into a very nice FAQ accordion. I seem to find a different one to like every time I need to design such a thing. [ed. note: sottwell last edited this post 14 years, 2 months ago.]
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 19369
        • 1,098 Posts
        I would use MultiTV for the Back End, and a jQuery accordion for the Front End.
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Hmm. Nice.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 3749
            • 24,544 Posts
            If you're using makeURL(), it's usually recommended to use it like this:


            $modx->makeUrl(71, "", "", "full");





            ------------------------------------------------------------------------------------------
            PLEASE, PLEASE specify the version of MODX you are using.
            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
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              I stand corrected wink
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 40395
                • 67 Posts
                Cheeers all.

                Back to the drawing board then, shame as it seemed that it was 'almost' working ;-)

                I'm a lot rusty when it comes to code but I'll try and work through a solution with one of the tools above.
                  • 9207 ☆ A M B ☆
                  • 2,475 Posts
                  I've seen some problems crop up when using "#" anchor links and the HTML base tag. Does the anchor work if you disable Friendly URLs?
                    • 40395
                    • 67 Posts
                    Quote from: Everettg_99 at Jul 06, 2012, 10:07 AM
                    I've seen some problems crop up when using "#" anchor links and the HTML base tag. Does the anchor work if you disable Friendly URLs?

                    at the moment the anchors that are formatted seem to work correctly. My real problem is getting the URLs to output correctly.

                    Today's cunning plan was to just drop the raw php into the page template but it looks like the page templates only support html sad

                    As you can tell I need to understand how all this hangs together a little better !
                      • 3749
                      • 24,544 Posts
                      Just noticed a formatting problem in this line. You're missing the quotation mark after href=:


                      Instead of

                      echo($qparastart."<a href=[~71~]\"#".$faq[$row][$IDindex]."\">".$faq[$row][$qindex]."</a></p>");


                      I think you want this:

                      echo($qparastart."<a href=\"[~71~]\"#".$faq[$row][$IDindex]."\">".$faq[$row][$qindex]."</a></p>");



                      ------------------------------------------------------------------------------------------
                      PLEASE, PLEASE specify the version of MODX you are using.
                      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