We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44661
    • 31 Posts
    Hi,
    A newbie question (currently learning by developing simple snippets), but cannot figure the anwser out !

    I need to use [[++site_url]] in the snippet below to get the full url of an xml file resource to parse :

    <?php
    $myxmlfile='http://www.example.com/'.$myxmlfile;
    
    $myslider = simplexml_load_file($myxmlfile);
    
    $totals=count($myslider);
    
    for ($i = 0 ; $i < $totals ; $i++) {
    			
    $modx->setPlaceholder('url_slide',$myslider->SLIDE[$i]->URLSLIDE);
    $modx->setPlaceholder('pics_file',$myslider->SLIDE[$i]->PICSFILE);	
    $modx->setPlaceholder('pics_alt',$myslider->SLIDE[$i]->PICSALT);	
    $modx->setPlaceholder('pics_legende',$myslider->SLIDE[$i]->PICSLEGENDE);	
    $modx->setPlaceholder('pics_legende2',$myslider->SLIDE[$i]->PICSLEG2);
    
    $output .= $modx->getChunk('slider.slide');	
    			
    }
    
    return $output;


    The snippet is called this way : [[!slider? &myxmlfile=`slider-home.xml`]]

    When i replace http://www.example.com/ by [[++site_url]] it doesnt work !!
    (i haven't added any slash)

    When i use [[++site_url]] in a basic snippet e.g. including :
    $output ='[[++site_url]]'; return $output;
    it worls perfectly and prints (as it should) : http://www.example.com/

    What's wrong ??
    Thanks !

    This question has been answered by Everettg_99. See the first response.

    [ed. note: justinet last edited this post 13 years ago.]
    • discuss.answer
      • 9207 ☆ A M B ☆
      • 2,475 Posts
      You can't necessarily reference the '[[++site_url]]' string in a snippet -- it's "magic" comes from the MODX parser, which parses your content and templates, but not your PHP code in a Snippet. The good news is that all those special placeholders are available as MODX system settings or as PHP constants or both.

      $site_url = $modx->getOption('site_url');
      // or
      $site_url = MODX_BASE_URL;
      


      For what it's worth, you might be able to get your full url using MODX's makeUrl() function: http://rtfm.modx.com/revolution/2.x/developing-in-modx/other-development-resources/class-reference/modx/modx.makeurl

      If you're linking to a MODX document, you can get the full URL by verbosely setting the "schema" option:

      [[~123? &schema=`full`]]
      


      You can get the same effect by adjusting the link_tag_schema system setting to "full".
        • 44661
        • 31 Posts
        Thanks Everett for your detailed anwser. Quite helpful !