My backup content (should the database fail) is brought in with include(). For some reason, there's a mysterious lone '1' below the div the include is wrapped in. It does it every time, but just on the content include. I've checked the function, all pages involved, no stray 1. If it loads from the database, everything's fine.
Any ideas why?
(empty($Content)?(empty($dbContent)?include($URL):$dbContent):$Content);
That's the core of the function. No code to provide really, just a strange 1.
Apparently it was the nested ternaries causing the issue. It outputs a 1 right after the function, as if it were saying echo include()
Very odd, because the rest of the functions seem to be working fine. The only difference is the include().
I'll switch back to longhand if any more odd behavior appears. It would be nice to know why it was treating it like it had echo in front of it.
Related
I have to make a template in the TinyButStrong language, but I have no access to the PHP side. I'm just able to modify my template and to upload it on my ERP.
Anyway, the PHP side is working well.
I tried to put an if statement in my ODT template file, but when rendering it doesn't work.
My condition:
[if [tab.product_type]!=1; then ‘[tab.product_ref]’; else ‘0’; block=table:table-row]
I verified value of tab.product_type, and the value is 0 or 1.
I tried many syntaxes, but none is working well. The only thing that it shows is:
.
Where did I make a mistake? I really don't understand, because I tried many syntaxes and I still get this line.
Little update :
I saw that the "when" is more adapted to this usage.
I found a syntax but I'm still having bad results. I made this :
[tab.product_ref;block=table:table-row;when [tab.product_type]!=1]
Anyway, it's giving me lines where tab.product_type is 1.
Why ?? I really don't understand how this language works...
What I keep seeing is something like
<?php $page_title = ""; ?>
<?php include_once("inc/header.php"); /* Include Header */ ?>
versus
<?php
$page_title = "";
include_once("inc/header.php"); /* Include Header */
?>
I assume there is no difference in functionality (not sure however), but which way is more semantic / correct does it matter if you declare all your PHP in several PHP blocks or a single one? Is performance affected in any way?
This is a major reason why doing your PHP inline is going out of style. There's no performance hit that I know of. All <?php ?> does is tell the interpreter that this is to be processed by PHP so your first code block is saying
Stop parsing PHP
Start Parsing PHP
I would imagine there's some miniscule hit somewhere if you're trying to wring every last ounce of efficiency out but I consider it to be insignificant. It's important to userstand that if you're using opcode cache (and you should) then the only hit is on the parsing side. Repeated execution of cache will have 0 effect here.
Readability, however, really does demand your code be as compact as possible. Remember, someone may come behind you and work on this code. Having two blocks where only one is needed is inefficient.
There is no real answer to this.
Some people like to have it the "Code-Block"-Way and put it all in one set of tags, some other people prefer the "HTML-Tag"-Way where they put each command in a new set of tags
There is no difference in functionality except for the fact that everything between one ?> and the next <?php gets echo'ed (So you have a lot of spaces in your output HTML, which is okay, since they are ignored)
Performance might be affected, but in numbers you really don't need to care about.
Generally, if you are in templates (or lets say, PHTML, HTML and PHP mixed), try to keep all commands single-lined (Put all single commands in <?php ?> and on own lines), this will make it more readable between all those HTML tags.
If you don't have HTML in your PHP file, there is no reason to enclose all commands with PHP tags
I have this code in a template
[[+isShowMore:is=`1`:then=`show more`:else=`no`]]
It is printing no. But it should show show more as placeholder isShowMore is set to 1 by this line of code in a snippet.
$modx->setPlaceHolder('isShowMore', 1);
Also checked by this code
[[+isShowMore]]
[[+isShowMore:is=`1`:then=`show more`:else=`no`]]
[[+isShowMore]] is printing 1 but the line with output modifier showing no.
Any clue what is wrong here? I am using modx revolution 2.2.8 traditional.
Similar issue is also posted in modx forum.
http://forums.modx.com/thread/85150/output-filter-on-placeholder-problem#dis-post-469615
I had this problem; my page was using a template that had [[*content]]. Changing that to [[!*content]] to get rid of caching solved my issue.
FYI, my snippet is being called with ! so that its output isn't cached either.
Are you doing that conditional inside another conditional somehow? Nesting conditionals usually cause this type of weird problem. Have you tried calling both your snippet and the placeholder output uncached?
I've also experienced this several times and there doesn't seem to be an obvious cause, some unknown magic in the modx output conditional logic. Experience has taught me to simply try to avoid using them as much as I can.
It's ugly but perhaps you could work around your problem by placing whatever you wish to output in the actual placeholder and then just printing the placeholder as it is.
Not sure why this doesn't work in your case so I recommend you do it with a snippet.
[[EvalIsShowMore? &val=`[[+isShowMore]]`]]
in EvalIsShowMore snippet put something like
<?php
if($val){
echo 'something';
}else{
echo 'nothing';
}
Hm, probably your placeholder is located above snippet!
In Modx output occurs at the last moment, but the logic works consistently (cascade).
Here's an example of how to do:
[[+isShowMore]]
[[!yourSnippet]]
[[+isShowMore:is=`1`:then=`show more`:else=`no`:toPlaceholder=`isShowMore`]]
another example:
[[+snippet_placeholder1]]
[[!snippet]]
[[+snippet_placeholder1:add=`[[+snippet_placeholder2]]`:toPlaceholder=`snippet_placeholder1`]]
give the eq modifier a try:
[[+isShowMore:eq=`1`:then=`show more`:else=`no`]]
The following code
<?php
echo ((12+1)%12)."<br/>";
echo ((12+1) % 12)."<br/>";
?>
leads to an unexpected result (13,1) instead of (1,1) on phpfiddle.org but it runs as expected on my server.
http://phpfiddle.org/lite/code/qdb-s4t
Is this an error in their sandbox or does it have to do with different php versions? How is the case without spaces interpreted?
I was just looking at some code for quite a long time and couldn't understand what was the difference.
i know i could use fmod or other sandboxes like http://ideone.com/.
PHPFiddle is just a website that is attempting to provide an easy way to execute PHP code samples from the browser. This isn't going to give you native behavior, simply because the code is going to be processed by JavaScript first using whatever logic the people at PHPFiddle seem fit. This leads to the possibility of bugs that have nothing to do with PHP and that is what is going on here. If you turn those same lines of codes into full strings, you will see the output still isn't even correct.
This is a very weird error. I am dealing with a script that uses variable $s as on object. This script has been running for a long time.
Randomly, on the page it suddenly said:
Trying to get property of non-object...
Confused, I put var_dump($s) on several places throughout the script, including the VERY TOP (before any includes or anything).
The output: string(32) "8251ca989c1e9aec382f07f6e047e5f3"
Even more confused, I put the var_dump($s) in another script to test it. Once again, it showed the same 32 character string.
What is happening here? Is this a hack of some kind?
EDIT:
I made a new script and this is LITERALLY the entire code:
<?php
var_dump($s);
?>
When I visit in a browser it says: string(32) "8251ca989c1e9aec382f07f6e047e5f3"
register_globals might be turned on, and the data might be coming from a cookie of the same name. You should disable it if you can for security reasons.