Hi,
I am newish to CMS, meaning I can now use the simple features with ease, but am not that sure how to make and use resources (other than ones that have already been made).
So basically I am making a website that show cases my designs, and the designs are stored in a database, now its important to keep in mind that I want to be able to use only one template (so i don’t really want to design a whole template just for showing designs). I’d prefer something like a plugin or snippet, but i’m really not sure which to use as they only seam to be able to output to a variable ($output) as far as I can tell from looking at other "resources". I know what the php code would be to output this into a table form of say <supplied variable> (columns)x<supplied variable>(rows) but I don’t know how to change that into modx php code, so if anyone out there can help me with that I’d really appreciate it.
And at least a hint to which "resource" to use would be helpful - because it has to be called by several pages I make which will basicaly instruct it as to which design to show and which page it should show (if it can’t fit in one page).
Thanks, James.
-
☆ A M B ☆
- 24,524 Posts
You’ll need a snippet to access the database and build the desired output into a variable from the results. Once the output is built, return it. You can also use echo statements in a snippet, but they sometimes will display in unexpected locations. Building up the entire HTML output into a variable then returning it is more reliable. Then put the snippet’s tags in the document content where you want this output to appear. I presume you are familiar with PHP and MySQL programming?
If you really want to get fancy, instead of building the HTML you can take all the values from the database and use the $modx->setPlaceholder(’placeholderName’, $value) function then use a chunk or a document’s content and use the placeholders to display the data, as Wayfinder and Ditto do. You can look at the code for those to see how data is retrieved and formatted for display.
Plugins are to interrupt the processing of the document parser, or do things when various events occur such as logging in or logging out. That’s not what you want here.
Ok, thats great, thanks I’ve now found out how that works qutie a bit better now, thanks.
Because the page modifier is html only i’m not sure how to parse, for example, $_GET(’page’) as i put that in the snippet and it really messed it all up; "Fatal error: Function name must be a string in /***/manager/includes/document.parser.class.inc.php(769) : eval()’d code on line 2".
And also how do i give it variables because I think i’ve seen something like [[Snippet something=anotherthing]], (could someone tell me if that syntax is right please, and how to then grab that variable from inside the snippet.
Thanks, James.
-
☆ A M B ☆
- 24,524 Posts
[[Snippet? &something=`anotherthing`]]
&something=`anotherthing` simply becomes a variable $something, with a value of whatever value was in the parameter.
$something = isset($something) ? $something : 'default'; // for if it's not set in the parameters
As far as the error on line 2 of your snippet, I’d have to see the code to know what’s going on. A snippet can pick up $_GET and $_POST just fine.
-
☆ A M B ☆
- 24,524 Posts
The () makes PHP think it’s a function, and you’ve got the variable name backwards. Try this
$output='hi'.$_GET['page'];
-
☆ A M B ☆
- 24,524 Posts
I would imagine that would be done in the code you generate for each row of the query results. You could put it in tables, or use divs and manage it with CSS, whatever you choose to generate.
Sorry i don’t think i put that very well, i mean how the HTML itself looks (the actual code) so that that is tabbed so I, the coder, can look back at it and easily see whats happening and where. How is that done through a variable?
(for example in php you use \n for a new line in the code and \t for as a tab in the code.
Thanks, James.