Alternative view.php for a single page in 5.8.0.2
Permalink
I am building a new website in 5.8.0.2 this is going well but I have hit a problem. I have a requirement for a specific single page which has a minimal header and footer, I have added a new single page, added a single page controller and all is fine so far. If I then add a reduced version of if view.php renamed as the single page name into the active theme this is when I hit issues. I have done some experiments and have established that when I try accessing the single page I am in fact directly loading the renamed view.php and not the single page. This is not new to me as an approach, I have done this numerous times in previous versions of C5. Looking at the docs they even say that the theme file will override the single page. So the question is what am I doing wrong?
Thanks
Thanks
Hi FaganSystems,
I recommend reviewing the Single Page documentation:
http://documentation.concrete5.org/developers/working-with-pages/si...
It appears that the view.php file in the active theme is used for displaying single pages. Where "echo $innerContent;", in the view.php file, is where the single page view content is "injected" and displayed.
Example:
- single page view
muffin.php
application\single_pages\muffin.php
- single page controller
muffin.php
application\controllers\single_page\muffin.php
After you create the "Muffin" single page, it should display "I'm a muffin" in the center left of the page. The content of the muffin.php view will be injected into the theme view.php using $innerContent.
It looks like you can render single page views using custom theme view files using the name of the single page view file.
Example:
- single page view
muffin.php
application\single_pages\muffin.php
- custom theme single page view
muffin.php
application\themes\elemental\muffin.php
- single page controller
muffin.php
application\controllers\single_page\muffin.php
The Muffin single page should be all red except for the text "I'm a muffin".
I recommend reviewing the Single Page documentation:
http://documentation.concrete5.org/developers/working-with-pages/si...
It appears that the view.php file in the active theme is used for displaying single pages. Where "echo $innerContent;", in the view.php file, is where the single page view content is "injected" and displayed.
Example:
- single page view
muffin.php
application\single_pages\muffin.php
- single page controller
muffin.php
application\controllers\single_page\muffin.php
<?php namespace Application\Controller\SinglePage; use Concrete\Core\Page\Controller\PageController; class Muffin extends PageController { public function view() { $this->set('test', 'I\'m a muffin'); } }
After you create the "Muffin" single page, it should display "I'm a muffin" in the center left of the page. The content of the muffin.php view will be injected into the theme view.php using $innerContent.
It looks like you can render single page views using custom theme view files using the name of the single page view file.
Example:
- single page view
muffin.php
application\single_pages\muffin.php
- custom theme single page view
muffin.php
application\themes\elemental\muffin.php
- single page controller
muffin.php
application\controllers\single_page\muffin.php
<?php namespace Application\Controller\SinglePage; use Concrete\Core\Page\Controller\PageController; class Muffin extends PageController { public function view() { $this->set('test', 'I\'m a muffin'); } }
The Muffin single page should be all red except for the text "I'm a muffin".
HI,
Its fine upto
"It looks like you can render single page views using custom theme view files using the name of the single page view file."
This is where things differ when you add the custom view into the theme folder the file is used to generate and render the content. I have proved this by changing the content in the file single_pages/muffin.php
After doing this you would expect to get a different content but nothing changes.
If I rename the file single_pages/muffin.php I would expect to get a 404 but again nothing changes and the single page controller content is still rendered.
So I conclude that the statement in the documentation herehttp://documentation.concrete5.org/developers/working-with-pages/si...
Means exactly what it says in that the custom view in the theme folder does take over the role of generating and rendering single page content replacing the single page. Is this a bug or an intentional change, or something I am doing wrong?
"Want to change this? You can. If you need more flexible control over a single page within a particular theme, just include a file with the same name as your single page within the theme itself. That entirely file will be used as the single pages template, including the header, footer, etc... It can completely override the single page, too. (So, in our example above, once we have "media" added as a single page, add "media.php" to your active theme. This template will then be used instead of the single page."
Its fine upto
"It looks like you can render single page views using custom theme view files using the name of the single page view file."
This is where things differ when you add the custom view into the theme folder the file is used to generate and render the content. I have proved this by changing the content in the file single_pages/muffin.php
After doing this you would expect to get a different content but nothing changes.
If I rename the file single_pages/muffin.php I would expect to get a 404 but again nothing changes and the single page controller content is still rendered.
So I conclude that the statement in the documentation herehttp://documentation.concrete5.org/developers/working-with-pages/si...
Means exactly what it says in that the custom view in the theme folder does take over the role of generating and rendering single page content replacing the single page. Is this a bug or an intentional change, or something I am doing wrong?
"Want to change this? You can. If you need more flexible control over a single page within a particular theme, just include a file with the same name as your single page within the theme itself. That entirely file will be used as the single pages template, including the header, footer, etc... It can completely override the single page, too. (So, in our example above, once we have "media" added as a single page, add "media.php" to your active theme. This template will then be used instead of the single page."
@FaganSystems
Where are you putting the custom theme single page view?
Here is an example using the free Stucco theme. The Stucco theme is installed and activated.
Example:
- single page view
muffin.php
application\single_pages\muffin.php
- custom theme single page view
muffin.php
packages\theme_stucco\themes\stucco\muffin.php
- single page controller
muffin.php
application\controllers\single_page\muffin.php
I edited the code examples to include a style tag to make the body background red, making the custom view hard to miss.
Where are you putting the custom theme single page view?
Here is an example using the free Stucco theme. The Stucco theme is installed and activated.
Example:
- single page view
muffin.php
application\single_pages\muffin.php
- custom theme single page view
muffin.php
packages\theme_stucco\themes\stucco\muffin.php
- single page controller
muffin.php
application\controllers\single_page\muffin.php
<?php namespace Application\Controller\SinglePage; use Concrete\Core\Page\Controller\PageController; class Muffin extends PageController { public function view() { $this->set('test', 'I\'m a muffin'); } }
I edited the code examples to include a style tag to make the body background red, making the custom view hard to miss.
HI,
to adopt your example,
when I had
application\single_pages\muffin.php & application\controllers\single_page\muffin.php
I will see the string "I'm a muffin"
When I add packages\theme_stucco\themes\stucco\muffin.php
I get a red background but no text.
I am using my own custom theme that I have been using since 5.7 with no previous issues.
I have also tried this with the default elemental clone clonelemental with the same results.
I am at a loss with this one, I had to continue building so the templated content is now in the singlepage 'view' file which is working well.
to adopt your example,
when I had
application\single_pages\muffin.php & application\controllers\single_page\muffin.php
I will see the string "I'm a muffin"
When I add packages\theme_stucco\themes\stucco\muffin.php
I get a red background but no text.
I am using my own custom theme that I have been using since 5.7 with no previous issues.
I have also tried this with the default elemental clone clonelemental with the same results.
I am at a loss with this one, I had to continue building so the templated content is now in the singlepage 'view' file which is working well.
I tested this by passing some content from the single page controller to the 'view' file and outputting this content.
Surely this is a different behaviour to 5.7? Where the 3 files retained their respective roles?
Thanks