Hi all,
Being a newbie to Drupal, I'm just a bit stuck with something . . .
In my usual world of adding php scripts to html pages, one of the things I regularly use is adding common content into variables, then using it on 100+ pages on the site
For instance, if the contact number of the site owner is 07886 556785 (not real, just made up!), I'd make this a php variable, then just use an echo function call for each and every page that I wanted to show the contact number on. Then if the number was changed, just one variable to change and hundreds of pages all update instantly. Wonderful!
How do we accomplish the same thing in Drupal?
I may have 500 content items that all refer to the same peice of information (a name, a number, an email address etc etc) and I don't want to have to do hundreds of changes when just one little bit of this changes
Any ideas?
I'm sure this will have been discussed, but I just can't find it!
Thanks very much
Biggy
Comments
Unclear on what you are after
Unclear on what you are after, that is how the variables are used or how they vary. Some of them maybe handled just by the way Drupal works. In general for things common to all pages you can just place them in page.tpl.php.
Thanks . . . a bit more info
Thanks vey much for replying
What I mean is storing a contact number as $main_num = "1234 56789"; for instance (and many others), in a seperate php file. Then I'd include that file for each and every page of the site, so the content of these 'variable' strings become available to hundreds of pages
Wherever I want to have the contact number printed on the page, I can just use an 'echo' function to display it. This could be on hundreds of pages. At some time the client may change numbers. With php, I just open the file and change $main_num to the new number . . . a couple of seconds, and I've updated the entire site
Can this be achieved with Drupal?
Can we access the contents of variables that we set up so they become available within content items?
I'm not yet sure what page.tpl.php is all about!
Thanks
Biggy
page.tpl.php or custom filter
As nevets stated, you can place your variables in your page.tpl.php file and they will be loaded in all pages.
You can also look into the following: http://drupal.org/node/210551, which would allow you to do the same without mucking around in PHP. This is a good option if you want others to be able to make changes without giving them access to your Drupal source code. I believe there are other modules that do something similar as well.
Thanks!
Thanks to both of you for your help. I'll have a lot of fun digging around with this
Biggy
Still no joy with this . . .
Any help would be very much appreciated
I'm trying to figure out how I can set several php 'variables' and use them throughout a site in any content or side block items that are displayed
For instance, I have the variable
$numbers = "12345";I'd like to be able to make reference to this variable in many different content items, so that the text displayed can include the data in this variable. This way, if a phone number etc changes, a quick cahange to $numbers, and every content item can display the new data
I've found the 'input filters' for content and allowed php code for the content items
I've also looked at the relevant "page.tpl.php" for the theme I'm using, but try as I might, I can't get the data in the variable to display in the content item rendered on the page
Is there any certain place in page.tpl.php that I should add the code? Is there another setting that I haven't found?
Once again, thanks very much for any help
Biggy
I suspect you need to use global
I suspect you need to use global, both where you declare and where you use the variable.
But I also wonder if you should check out the custom filter module mentioned above. It seems like it would allow you to do what you want without needing to use the 'PHP input filter' all over the place and it provides an admin interface for the replacement rules so you could change values from within the Drupal interface.
Thanks
OK, I'll keep on with the filter module and work my way around it!
Thanks
I'm trying to do this exact
I'm trying to do this exact same thing. I have some custom variables in my content (PHP). Has anyone found a solution?
Anyone? I've tried adding my
Anyone? I've tried adding my variables to all the template files, it doesn't work.
Where can I put my own variables so my PHP content can access them?
$content is created before any template file
$content is created before any template file, so, if you declare a variable in a template file, it couldn't be read when you edit content in admin panel. i've the same problem, and i haven't found any solution yet
happy new year
Great blogs! Please see my blogs here: http://cncrouters.bloghi.com/