Overview of running PHP inside autonav block code?
Permalink
I am playing around with various capabilities of C5 to better understand it's inner workings (and give me extra flexibility in using it to meet my own as well as client needs) and was wondering if someone could give me an overview of how one might run PHP code inside block page HTML code?
I know it is possible as there is a block in the marketplace that seems to do just that.
Anyway...in the following code...
The PHP echoing the server host name works just fine in the default.php file.
But the same line put into the HTML code inside the Left Sidebar block (it's a autonav block) doesn't work.
So how (again I am looking for an overview and not a line by line detailed analysis) does C5 process the block HTML such that the line of PHP code is not run from within default.php??
I would think C5 would insert the block HTML (including any PHP statements inside it) and then execute default.php (with all it's PHP statements).
But apparently not.
Somehow C5 executes the PHP code in the default.php file seperate from the PHP code that might be inside block HTML which it ignores but how it does that while still executing default.php overall is a bit of a mystery to me at this point.
Any insight would be appreciated.
Thanks.
Carlos
I know it is possible as there is a block in the marketplace that seems to do just that.
Anyway...in the following code...
<?php echo "http://".$_SERVER['HTTP_HOST']; ?> <?php $a = new Area('Left Sidebar'); //$a->setBlockWrapperStart('<div id="left-sidebar">'); //$a->setBlockWrapperEnd('</div>'); $a->display($c); ?>
The PHP echoing the server host name works just fine in the default.php file.
But the same line put into the HTML code inside the Left Sidebar block (it's a autonav block) doesn't work.
So how (again I am looking for an overview and not a line by line detailed analysis) does C5 process the block HTML such that the line of PHP code is not run from within default.php??
I would think C5 would insert the block HTML (including any PHP statements inside it) and then execute default.php (with all it's PHP statements).
But apparently not.
Somehow C5 executes the PHP code in the default.php file seperate from the PHP code that might be inside block HTML which it ignores but how it does that while still executing default.php overall is a bit of a mystery to me at this point.
Any insight would be appreciated.
Thanks.
Carlos
Howdy BigBobby.
The PHP code within default.php obviously gets executed as...well...PHP code should.
But if I put some PHP code (whatever that is or whatever the reason) into the HTML code inside an HTML block...well...that PHP code is not executed even when C5 incorporates it (inserts it, includes it) into the default.php file through the new Area() code snippet.
I am wondering why it is not executed along with the rest of the PHP code inside default.php and more importantly am looking for an overview of how to execute PHP code inside the HTML code inside an HTML block.
I hope that makes more sense.
Carlos
The PHP code within default.php obviously gets executed as...well...PHP code should.
But if I put some PHP code (whatever that is or whatever the reason) into the HTML code inside an HTML block...well...that PHP code is not executed even when C5 incorporates it (inserts it, includes it) into the default.php file through the new Area() code snippet.
I am wondering why it is not executed along with the rest of the PHP code inside default.php and more importantly am looking for an overview of how to execute PHP code inside the HTML code inside an HTML block.
I hope that makes more sense.
Carlos
Makes a lot more sense!
Yeah.. the html block won't run the scripts. Not sure why...
But there's an add-on that gives you a similar block that does just this:
http://www.concrete5.org/marketplace/addons/simple-php-block/...
Yeah.. the html block won't run the scripts. Not sure why...
But there's an add-on that gives you a similar block that does just this:
http://www.concrete5.org/marketplace/addons/simple-php-block/...
I appreciate the tip on the add-on. It's nice and all but quite frankly I don't want to have to pay $15 every time for every use on every web site.
I'd rather roll my own.
Carlos
PS. Hmm...I suppose I could buy the add-on and study it's code but if the code for the add-on is anything like trying to understand the code of C5 itself...that will be one incredible pain to do. No insult intended to anyone here...C5 as an interface is great but the code is really hard to work with in that it is very poorly documented and such that there are pieces of code coming from all kinds of files being put together to render a web page.
I'd rather roll my own.
Carlos
PS. Hmm...I suppose I could buy the add-on and study it's code but if the code for the add-on is anything like trying to understand the code of C5 itself...that will be one incredible pain to do. No insult intended to anyone here...C5 as an interface is great but the code is really hard to work with in that it is very poorly documented and such that there are pieces of code coming from all kinds of files being put together to render a web page.
Last time I looked (2 seconds ago), it was free.
Oops! I must have looked at a different one. I didn't realize there was a free one.
I will definitely install that one and start a studying what it does so that I can imitate the parts I want to use (while discarding the rest).
Thanks!
Carlos
I will definitely install that one and start a studying what it does so that I can imitate the parts I want to use (while discarding the rest).
Thanks!
Carlos
Your post is a little confusing to me...
Default.php is, obviously, a template file. By defining a new area within that template you create an editable area.
Any other php code within defatault.php will be executed as in any other php file.
php entered into an html block on the front end doesn't get executed.
If you want to edit the output of the autonav, or any other C5 block, you can save that block's view.php to the /blocks/block_name folder to override that block's default view, or you can save it to /blocks/block_name/templates/template_name and then invoke that custom template on the front end by selecting "custom template" from the editing dialog.
Not sure if this answers your question, but when you're talking about php code in block html it's very confusing...