We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30399
    • 23 Posts
    Quote from: smashingred at Feb 16, 2010, 07:58 AM

    You can pass variables to a page so long as the php script you have is either in a snippet or using the API. Don’t get hung up on file extensions as they are purely abstract for the purposes of friendly URLs when you have fURLs enabled. It uses Apache mod_rewrite to give a file an extension so even though your file has the extension .html or php they are both php files rendered via /index.php. Giving a page a php extension doesn’t do any thing but change the friendly url. You could call your files .pizza or .joe or whatever you want it is still parsed by the MODx parser.

    This is a user contributed document on how to Create a Snippet. Snippets are php scripts that perform any logic you want done on a page and you access them by calling them using the following Syntax: [[SnippetName? &parameter=`` &parameter2=``]] etc. Parameters are any value you wish to pass from the individual to the snippet. There need not be any parameters if the snippet doesn’t need values from the document.

    Thanks Smashingred. I understanding the basics of creating snippets - I have two snippets now, for pulling data from mySQL. But I don’t see how to pass the variable from within a page of generated html to a snippet, without using something like this method:

    while ( $row = mysql_fetch_array($result) ) {
    echo ("<a href=’" . $MyUrl . "?usastate=$row[1]’>$row[1]</a>
    ");
    }

    This php generates a list of the US States as clickable anchors. I use the State name, in $row[1], as the anchor text. The page in $MyUrl is named as a .php because without that .php extension, this stuff did not work, which makes sense.

    Is there another way ??