I have template variables for when an office opens and closes every day of the week. To select, you choose, for example, Monday Start and you have a drop down with a list of every half hour (ie 7:00 AM||7:30 AM||8:00 AM …
Within the template I have a snippet which I pass those times to, for an example 8:00 AM. When I try to explode on the colon “:” $x = explode(“:”,$variable), $x[0] returns “8:00 AM”, not 8. I tried to perform a substr command on the variable, and that will not work. Finally I did an if ($x == “8:00 AM”) { echo “True”; } else { echo “False” } and it returns False. I’ve checked for hidden characters but don’t see any.
So if landing.sundayam is a template variable and you’re running the snippet “Hours” directly in the template, you have to use [[*landing.sundayam]] (with the *) instead of the placeholder tag [[+landing.sundayam]] (with the +).
[[*tvName]] is the MODX tag for a TV or a resource field. [[+placeholder]] is the tag for a placeholder. To use a placeholder, it must be set first (e.g. in a snippet) before it can be used.
My guess is, that when your snippet “Hours” runs, the properties still have the values “[[+landing.sundayam]]” and that the placeholders haven’t been replaced with the actual values (like e.g. “8:00 AM”) yet.
So yes, the * does not pass a variable, but the + does. I just don’t understand the issue. It appears to be a string. I have check for hidden characters and there are none. But I can not do any type of string manipulation on that variable.
If by any chance you set this placeholders in a snippet you call uncached, then call “Hours” also uncached (which you should do anyway) and use uncached placeholder tags ([[!+landing.sundayam]])
Yes, it’s probably the string “[[+landing.sundayam]]”.
Maybe log the values to confirm it → $modx->log(modX::LOG_LEVEL_ERROR, 'Value of $open_time is: ' . $open_time);
This is a website for a local government. There is the main index page, and then each department has its own landing page (but I do not want to make individual contexts for each department). Accordingly, on the main index page, and the sub-landing pages (for each department) are template variables that hold the data for what should be displayed in the footer, an alert which appears at the top of each page of a specific department, etc. When a page is displayed it first looks for the parent document which is of a specific template (sub-landing page or index) and pulls those template variables for its sub-pages.
You have to make sure, that the placeholders are set before they are used.
The MODX parser first parses the cached tags, only then it parses the uncached tags.
Thanks halftrained. The snippet call to set the placeholders is the very first line in my template. Thanks to your help I have identified that the value being passed to my Hours snippet is the NAME of the template variable rather than the value. Now the questions is how to make, for example:
[[Hours?
&sunstart=`[[+landing.sundayam]]`
]]
pass the value of “Closed” instead of passing “[[+landing.sundayam]]”
So now you should change everything to uncached to make it really work.
(Your snippet “Hours” depends on the current time (time()), so it has to run uncached.)
Also maybe read this article (especially the “parsing order” section) to better understand how the MODX parser works.
Just out of curiosity, did you consider putting the HTML to display the times for a whole week in a single text TV, displayed with a single tag? That would probably decrease page-load time, since it would do the job with no code and no calculations. On the other hand, though, it would take up more screen real estate.
It’s an interesting case, because there are so many different ways to do it. My first thought was to put the snippet tag where where you want the value displayed, and get the desired TV value directly in the snippet by querying the modTemplateVarResource table (modx_site_tmplvar_contentvalues table), then just return the value. I’m not sure that’s any better than what you did.
Thank you for the feedback. Since the hours change depending on the department I am writing a script which first shows if they are open, opening soon, closing soon or closed and then grouping like hours together, so if Monday through Friday has the same hours it would show Mon-Fri - 8:00 AM - 5:00 PM to save real estate.