I would like to be able to split my site into sections and for each section apply different custom PHP code to the theme, what I mean is:
I would like to be able to create - if you like - sections, the only purpose of these is to allow me to apply custom php code to a theme, for each section the code will be different that is applied to the theme. Sections are defined by a list of urls that each section will be applied to. I would like to be able to apply some sections to a content type.
Anyone help.
Thanks,
Azz McH
Note: This forum topic nearer the end changed into a discussion about text editors, after the problem that this conversation was previously about, I managed to fix it.
Please continue this conversation at What text editor do you use? Why?, not here.
Comments
=-=
modules to investigate
sections.module
themekey.module
Though, I don't know if either of those module are available for the version of drupal you've installed because you failed to tag the thread nor make mention of which version is in use.
there are likely multiple ways to do what you ask. Checking out the theme documentation where it concerns template suggestions will likely help
Thanks, i set the version. I
Thanks, i set the version.
I already use the theme key module, the sections module is ok, however the only PHP code it allows me to insert is PHP code that affects which pages that section is applied to: in my theme I have set variables that allow parts of the theme to be shown or hidden. The sections module does not allow a section to be applied to a specific content type.
=-=
custom tpl.php files may be required
As far as I know, they will
As far as I know, they will only allow me to edit the content of the page, not all the code.
=-=
sounds like you need to read a little deeper. Content is edited by editing a node. tpl.php files handle presentation and allow for adding HTML and PHP.
What is wrong with creating
What is wrong with creating different page.tpl.php and isolating the code into template.php? If this is the appoarch you want to take then you should let us know. For example, my site has a classified section and that has it's own page-ed-classified.tpl.php file where I can utilize the 960 framework to create different layouts. My custom php is rendered into either the template.php file or in a block with a php filter.
There is a proprocess function that allows developers to create different ways to get information into variables that can be used to render dynamic code in a tpl.php file. It's a fairly standard and straight forward technique. I not going to go into it now because I don't know if that is really what you want.
Can the contemplate module solve the problem your working with?
You will have to explain yourself better. There are several ways in Drupal to solve any problem but we need to be clear on what you want to achieve. Perhaps, you can give us an example of a website that has what you want.
The site
How does using page.tpl.php files work, I was aware that you can only have one page.tpl.php file.
My current solutions is to have one theme called "Chrome", and - if you think of it this way - sub-themes, e.g. "Chrom - Forums". Each .tpl.php file in the 'sub-theme' only contains the php include function to get the contents of the same .tpl.php file in the 'main-theme' (chrome). Each sub-theme is essentially an independent theme. The purpose of this is in the page.tpl.php file, of each sub-theme variables that have been setup in the main-theme (Chrome) are defined, e.g. to hide the breadcrumb the $showbreadcrumb variable would be set to false. Therefor when the user requests a page that a sub-theme has been applied to, in this case the breadcrumb would be hidden. I use the themekey and nodetypetheme modules on my site, so theming my site this way seemed the most practical way to theme.
The problem began around about Friday evening, for no reason, only on Internet Explorer the main-theme is fine, however the sub-themes, IE seems to have a problem with a few styles and AJAX. I have also noticed that drupal inserts blank lines into my theme on output creating white space in specific locations. I have no idea why Drupal is doing this, below is the results from the W3C Validator validation on the home page of my site:
W3C Validation for my site:
Notes and Potential Issues
The following notes and warnings highlight missing or conflicting information which caused the validator to perform some guesswork prior to validation. If the guess or fallback is incorrect, it could make validation results entirely incoherent. It is highly recommended to check these potential issues, and, if necessary, fix them and re-validate the document.
Byte-Order Mark found in UTF-8 File.
The Unicode Byte-Order Mark (BOM) in UTF-8 encoded files is known to cause problems for some text editors and older browsers. You may want to consider avoiding its use until it is better supported.
Validation Output: 3 Errors
Line 1, Column 1: character "" not allowed in prolog
Line 46, Column 1: character data is not allowed here
<!-- Start of MFHweb GHeader Linked Files //-->
You have used character data somewhere it is not permitted to appear. Mistakes that can cause this error include:
putting text directly in the body of the document without wrapping it in a container element (such as a <p>aragraph</p>), or
forgetting to quote an attribute value (where characters such as "%" and "/" are common, but cannot appear without surrounding quotes), or
using XHTML-style self-closing tags (such as <meta ... />) in HTML 4.01 or earlier. To fix, remove the extra slash ('/') character. For more information about the reasons for this, see Empty elements in SGML, HTML, XML, and XHTML.
Line 1, Column 2: XML Parsing Error: Start tag expected, '<' not found
Could this have anything to do with why I have this problem on IE?
Thanks
Azz McH
First, with open source CMS
First, with open source CMS it's a lot of work to get validated. Drupal.org doesn't validate. I wouldn't worry about it too much.
When Drupal parses all the file names in a themes folder, it uses that information to determine when those files should be loaded. Your main page will be page.tpl.php. If you have a video page http://example.com/video that requires a different template then you can have it loaded by naming convention or page-video.tpl.php. When that url comes into the .htaccess php cuts of the /video and sends it to Drupal. If you have rebuilt the theme registry with the page-video.tpl.php in the theme folder, Drupal would have put the information into the a cache in the database. When Drupal figures out what to do with /video it finds that information in the database and loads all the right pages and modules and stuff.
You don't need a subtheme unless you want the different sections to be very unique. My site uses two completely different themes. If different sections have different layouts just create new page.tpl.php files. If you put a different class in the body or wrapper tags you can have complete different designs using only a few hundred lines of CSS which won't hurt performance at all.
Apart from having
Apart from having page.tpl.php could I also have page-<contenttype>.tpl.php files in the same theme just like block-right.tpl.php or block-left.tpl.php?
Follow-On From Last Post
This is a follow-on post from the last post.
This is the W3C Validator validation for a page that does not do this in IE and yet it uses a sub-theme.
W3C Validator validation:
Notes and Potential Issues
The following notes and warnings highlight missing or conflicting information which caused the validator to perform some guesswork prior to validation. If the guess or fallback is incorrect, it could make validation results entirely incoherent. It is highly recommended to check these potential issues, and, if necessary, fix them and re-validate the document.
Byte-Order Mark found in UTF-8 File.
The Unicode Byte-Order Mark (BOM) in UTF-8 encoded files is known to cause problems for some text editors and older browsers. You may want to consider avoiding its use until it is better supported.
Validation Output: 1 Error
Line 45, Column 1: character data is not allowed here
<!-- Start of MFHweb GHeader Linked Files //-->
You have used character data somewhere it is not permitted to appear. Mistakes that can cause this error include:
putting text directly in the body of the document without wrapping it in a container element (such as a <p>aragraph</p>), or
forgetting to quote an attribute value (where characters such as "%" and "/" are common, but cannot appear without surrounding quotes), or
using XHTML-style self-closing tags (such as ) in HTML 4.01 or earlier. To fix, remove the extra slash ('/') character. For more information about the reasons for this, see Empty elements in SGML, HTML, XML, and XHTML.
I don't know why this is the only sub-theme that does not cause problems, the validation is also the same for the main-theme.
_
There's quite a bit of misinformation in this thread. Instead of guessing it's worthwhile reading the documentation as VM suggested early on-- it may take a little more time upfront, but you'll save time in the long run.
You can have as many template files as you need or want--- drupal provides some by default. See http://drupal.org/node/190815 for the list of default templates. page.tpl.php files are not based on content type-- they are based on internal path, but you can add content type ones (or any others) if you need to. See http://drupal.org/node/223440 for more info.
And its definitely worth going through the http://drupal.org/theme-guide/6 -- if nothing else, you'll have an idea of what you can do and where to look when you need to do it.
So, to make sure I have this
So, to make sure I have this correct I would insert this code http://drupal.org/node/223440#comment-1045201 into e.g. page-forum.tpl.php or into page.tpl.php?
=-=
tias = try it and see
The above is the best way to learn what works and what doesn't. When it doesn't work as expected and you've reviewed the documentation you can then ask why it doens't work as expected or as documented. When referring to comments by other users it is important to take the date into consideration as some comments may be referring to an older version of drupal where it's possible things have changed.
may also be of benefit to watch this: http://acquia.com/community/resources/acquia-tv/tips-and-tricks-drupal-t... 90 minutes of themeing explaination
I have worked out what the
I have worked out what the problem that I am having is, the first two lines of the HTML output are shown bellow:
Inside the quotes there is a character that is not represented and in Notepad comes up with a square, in other words the character cannot be represented. This is occurring though out the theme, at several points.
Does anyone have a solutions to that?
PS: This only occurs on a "sub-theme", look above to find out what I mean by sub-theme under "The Site" comment.
=-=
check the page.tpl.php file of the theme inside the head tag. May lead to clues.
I'v checked and there is no
I'v checked and there is no 'hidden' tags, another thing is when looking at the source code using Internet Explorer Developer Tools, everything inside the head tag appears in the body tag, except the title tag, doesn't happen in notepad when viewing the source code. Again only happens on the "sub-themes".
=-=
sub theme of what base theme?
if possible archive the subtheme and provide a link for someone to download and take a look. At this point I would just be guessing.
Fixed!
I'M SO HAPPY! I just fixed the main problem that I am having with my theme, somehow a couple of strange characters that every browser except IE doesn't process were inserted on line one of the page.tpl.php file on the "main-theme", before the doc type, and you know happens when things go above the doc type, lol. The only reason that I discovered it was just now when I was in the file manager on my server control panel and went into the page.tpl.php file. I use SharePoint Designer so my guess is that somehow those characters were inserted by SharePoint Designer.
Thanks for everyones help, much appreciated
Thanks
Azz McH
=-=
Dreamweaver, Sharepoint designer and the like aren't required. A simple text editor does the job.
I had the same problem here,
I had the same problem here, using notepad++
I solved it (eventually) by changing the format to "Encode in UTF-8 without BOM".
Thanks for the info. Aaron
Thanks for the info.
Aaron