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

    i want to use some php-code in entries ("ressources"), just like
    <p>bla this is the text of the ressource</p>
    <p>blabla</p>
    <?php echo "bla"; ?>
    <p>this would be nice</p>

    i don’t find anything in the forums or the documentation (but to be honest: it’s hard to search for terms like "use php ressource" smiley

    i am using modx revolution rc2.

    would appreciate help very much.
    thanks in advance!
      • 20413
      • 2,877 Posts
        @hawproductions | http://mrhaw.com/

        Infograph: MODX Advanced Install in 7 steps:
        http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

        Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
        http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
        • 3688
        • 43 Posts
        Thanks for the fast answer! I cannot use snippets or static ressources, because i have a lot of pages where i want to define some php-variable (for each page a different), e.g.
        <?php $filepath = "thepath/to/a-file/named/something.pdf" ?>
        <p>this stuff is always the <a href="<?php echo $filepath; ?>">same</a> and if i want to <a href="<?php echo $filepath; ?>download</a> this <a href="<?php echo $filepath; ?>file</a> i ...</p>
        


        it would be very much work to place (and occasionally REplace) the filepath 5 times on each page ...

        i hope this is understandable ... smiley
        is there maybe some other solution i could use?

        thanks in advance!
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          The snippet:
          <?php
          $filepath = "thepath/to/a-file/named/" . $something . ".pdf";
          $modx->setPlaceholder("filepath", $filepath);
          return;
          

          The snippet tags:
          [[setFilepath? &something=`file_root_name`]]
          The placeholder tags:
          [+filepath+]

          The snippet allows for a parameter to set the actual file root name; the path and filetype are hard-coded in the snippet.
            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
            • 18373 ☆ A M B ☆
            • 3,141 Posts
            Quote from: bnetz at Jul 02, 2010, 04:51 AM

            Thanks for the fast answer! I cannot use snippets or static ressources, because i have a lot of pages where i want to define some php-variable (for each page a different)

            What about Template Variables? You can link variables to templates, and every resource using that template will have its own value for the template variable. You can easily access it with [*tvname*].

            Some more info: http://svn.modxcms.com/docs/display/Evo1/Template+Variables
              Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

              Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
              • 3688
              • 43 Posts
              Thanks to all for the fast and friendly answers!

              I now managed it this way:
              1) Created a template-variable named "file_name", there i put the file-name (e.g. "bla.pdf").
              2) created a chunk named "embed_file", there i put this code (shortend, actually it is longer):
              <iframe src = "http://www.xy.de/[[*file_name]]#pagemode=none&toolbar=0&scrollbar=0&statusbar=0&messages=0&page=1&navpanes=0" width="550px" height="375px"  frameborder="0"></iframe>

              3) integrated the chunk into every ressource with
              [[$embed_file]]


              So this works as expected, and I am astonished how incredible easy and snappy this worked. I am new to MODx, just checking it out if i want to use it for some of my sites, and i guess when the 2.0 final release is out i will switch to modx.

              so again thank you very much for your support!!

              (my case closed)

              edit 02.07.2010:
              i now have the problem that i want to show the code ONLY when a file exists. you can find the discussion here