Why do changes to view.php not take effect?

Permalink
I have a single page with one auto-nav block on it (I have removed all links in that auto-nav except to the Home page).

I have two versions of view.php.

One inside /blocks/auto-nav/view.php and the other inside /concrete/auto-nav/view.php. They are identical except for the following:

I changed the code inside the first to read...

if (!$containsPages) {
            // this is the first time we've entered the loop so we print out the UL tag
            echo("<ul my block class=\"nav\">");
         }


I changed the code inside the second (or core view.php version) to read...

if (!$containsPages) {
            // this is the first time we've entered the loop so we print out the UL tag
            echo("<ul core block class=\"nav\">");
         }


Yet when I view the page in my browser I see this...

<div id="blockStyle57LeftSidebar3" class=" ccm-block-styles" > 
<ul class="nav"><li class="nav-selected nav-path-selected"><a class="nav-selected nav-path-selected"  href="/">Home</a></li></ul></div>


Why does C5 ignore the change in either my custom view.php or the core one and spit out a simple <ul class="nav"... instead of the expected <ul my block class... or <ul core block class...?

Anybody?

Thanks.

Carlos

 
ThemeGuru replied on at Permalink Reply
ThemeGuru
Well first of all for custom templates you should not put anything in the core. Leave that alone.

As for creating a new template don't use view.php use something more custom i.e. custom_menu.php.

Then apply your template.
jordanlev replied on at Permalink Best Answer Reply
jordanlev
A few things going on here...

If you created a file in /blocks/auto-nav/, it's not going to do anything -- it needs to be /blocks/autonav/ (wihtout the dash in the middle).

Once you have that, what's going to happen is that Concrete5 will ALWAYS use the view.php file in /blocks/autonav/, and never the one in /concrete/blocks/autonav/, because that's how the system is designed. If you want to be able to choose between the two, you need to make this instead:
/blocks/autonav/templates/some_name.php
(don't call it view.php in this scenario).
Then on the page with the autonav block that you want to give your alternative template to, enter edit mode, click on the autonav block, choose "Custom Template" from the popup menu, and select "Some Name" from the list.

Another thing is that this code:
<ul my block class=\"nav\">


is invalid html -- if you just throw random words inside the <ul ... >, it's going to be ignored by the browser. So when you say that you "view the page", I assume you mean that you're viewing the source of your page -- it's very possible that the browser is showing you the source AFTER it has filtered out all of the invalid things (such as the "core block" or "my block" inside the <ul> tag).

I think what you want instead is:
echo("<ul class=\"nav my block\">");


Hope that helps.

-Jordan
carlos123 replied on at Permalink Reply
Thanks for the reply you all. Much appreciated.

By the way...my directory names and otherwise were indeed correct though I may have added a "-" to the name when I posted in this thread by accident.

The reason I know that is because what I ultimately did is I deleted the autonav block from the page in question and then added a new autonav back again and voila...my code worked with respect to showing up as expected (it wasn't a cache thing as I have not only disabled that during development but I had also cleared it to no effect).

Although my code was invalid HTML I did it that way so that I could look at the source code of the page and see which one was creating the source code. Either the core or my custom template.

Also...for sure I should not modify the core code. I was just doing that to better discern what the core code was doing, if anything. As contrasted with my custom template code.

I still don't understand why deleting the block and then re-creating it "fixed" the problem (there's probably a bug of some sort in there somewhere) but I'll leave it at that. As long as it's working I won't chase it down as I have very limited time to do so this month.

One other thing I discovered (at another website) is that I could create a view.css to control the presentation of the nav UL put out by view.php (incidentally it doesn't seem to matter that I have named my custom file, view.php).

I never read that at concrete5 here in the documentation though such might be in there somewhere.

Does anyone know where such a thing is documented here and whether there are other files that could be created inside the autonav block code directories that might control this or that which might be handy to know about?

I guess I am wondering what other goodies I might be missing out on creating just because I don't know about them.

Carlos
jordanlev replied on at Permalink Reply
jordanlev
I'm not sure where it's documented exactly (hopefully some day there will be comprehensive docs that explain all this stuff, but there's not right now).

But in general you can override the following things for a block:
* view.php
* view.css
* view.js
* controller.php (probably best not to do this though)

You can also put any of those in the /templates/ subdirectory like I mentioned above to make them available as optional choices in the "Custom Template" menu.

Note that there is a bug in the current C5 system where if you override the view.php file, the system will then only look for the css and js files in the override directory -- so if you're overriding a block that has some custom javascript, you need to copy its javascript files to the new override template directory as well, even if you're not changing anything in there. (This may only apply to packages -- I can't remember off the top of my head).

-Jordan
carlos123 replied on at Permalink Reply
Thanks again Jordan.

Comprehensive docs are indeed missing and sorely needed but...once I figure all this stuff out, I may write them myself and post them up at an independent site to gain some benefit from taking the time to write them up.

I think that would be a real boon to C5.

The documentation here is okay but it assumes a huge amount of knowledge that even I don't have (and I am very familiar with and comfortable with PHP programming and have created lots of stuff in PHP). It uses terms that are like Greek to me but is written in such a way that an understanding of these terms is just...well...assumed.

The docs are worded in such a way that it is really difficult to understand and follow them I think.

Carlos
jordanlev replied on at Permalink Reply
jordanlev
If/when you write this up, please send me a link (PM me or email concrete@jordanlev.com). I am trying to put together some docs myself, but obviously it's a huge space so the more resources I can find by others, the better.

Thanks.

-Jordan
carlos123 replied on at Permalink Reply
It's going to be a while before I do much with that Jordan though I was thinking of just registering a domain and putting up what I learn as I learn it rather than waiting till I know a lot.

Otherwise I may never get it done.

I mean I do that for myself locally on my computer anyway using a Linux program called Zim which is like a personal wiki but I figure I could post it online for the benefit of all with a just a whee bit more work to get it online.

I'll see what I can do.

Carlos