By Brian Tastic on
I'm used to writing simple web sites procedural & OOP, but use PHP includes quite a lot to prevent repetition and ease maintenance. A quick search through the Drupal forums, one get's the impression using includes has been restricted in D6 for security reasons (can't think why if you are pointing directly to a file).
Can anyone tell me what I should use instead? I want to be able to point to a piece of PHP/HTML code from within nodes, so if I change that code, this change is reflected in every node that points to that code, you get the idea.
Pls bear in mind, I am not a coding junky, so I'm looking for simple alternatives only.
Thanks for any pointers.
Comments
Are you able to put the code
Are you able to put the code in page.tpl.php? This way you wont have to repeat yourself.
I don't think that would be
I don't think that would be very flexible because a 'snippet of code' would then apply to everything. I what to be able to place any 'php include() alternative' within various nodes as desired, just as well as placing them within template regions, for example.
I think that this might show
I think that this might show a flaw in your design. Putting it in the template would be the best option, but you could use a flag of some sort to indicate when the theme should include it (taxonomy, for example).
Yes, it's more complex, but it is better data design.
Hi Corey - I'm not sure I
Hi Corey - I'm not sure I understand
Do you mean place the 'php code snippets' or the 'reference to the snippet' inside say, 'template.php' ?
if the former, doesn't this mean that 'template.php' would potentially become massive, essentially becoming a code snippet repository? or if the latter, how do I point to the actual code snippets?
This problem is hard to
This problem is hard to answer, because we don't know more about your setup.
Here's the thought motivating my suggestion: Surely the process can be abstracted out so that so that you aren't having to write php includes directly into nodes. It's a security risk, even if yours is the only account posting to your site. If someone were to hack in, then you would want to slow them down as much as possible.
Using include() is not bad, per se. It's the idea of using PHP in a node that you want to avoid, and there are several ways of doing that, depending on what you want done.
You could do it with theming and taxonomy. You could do it with Blocks. You could do it with custom filters. You could write your own module to handle it. Or, yes, you could even do it by putting php into a node.
The thing is, there are many different ways to approach the problem, and the best solution can only be determined by examining not only what you are trying to do now, but how you will use this in the future.
PLEASE GIVE SOME SUGGESTIONS
Is there really no simple alternatives? Is the php include() function dead as far as Drupal 6 is concerned?
Are you familiar with Blocks?
Are you familiar with Blocks? I'm not if they will meet your need but they allow for conditional visibility of elements on your site.
Yes Blocks
Create a block, enable PHP for it. Put your code in there.
Assign the block to a region and control what pages the block appears on. When you need to change the php, edit the block.
I can't see how includes are better than this in any way. Just visit admin/build/block/add to start.
A list of some of the Drupal sites I have designed and/or developed can be viewed at motioncity.com
Thanks to everyone...
Thanks everybody for your input.
I think I'll explore the suggestion of using blocks, even though I haven't gone set one up manually yet, from what I've picked up here and there, hopefully it shouldn't be too difficult and it will fulfil my 'php include()' cravings :D