Forums / Setup & design / Dynamic Body ID

Dynamic Body ID

Author Message

Nathan Kelly

Thursday 12 May 2005 4:58:04 pm

Hi there,
I have searched the forums pretty extensively for the past 2 days looking for an answer to my problem (the first of many I imagine) but with no success, though maybe if I was a little more familiar with the EZsyntax I may have seen the answer in my travels.

Quite simply I need to be able to dynamically pull the body id from the current page URI, the reason for this is my menu is constructed with some very complex CSS to achieve the look I need.

So far I have found that I am able to pull the node name into the id="" but the problem with this is that some of my pages have more than one word in the name; for example the output would look like this-

<body id="about us">

    <div id="navigation">
    ....
    contents
    ....
    </div>

</body>

This is not much good to me for the obvious reason that CSS selectors are useless with a space in them. So I noticed EzP inserts a "_" into the spaces when cleaning up the URI therefore the page URI is the ideal element for an ID.

<body id="about_us">

    <div id="navigation">
    ....
    contents
    ....
    </div>

</body>

I have tried many different variations of the following code but to no avail, the best I have managed is something like "products/mens_wear", and extracting a portion of the name is no good because my top level navigation is so varied for example-
Products | About Us | Members Login etc...

{section loop=$node.path_array offset=2}
{let page_name=fetch( content, node, hash( node_id, $item ) )}
{run-once}
<body id="{$page_name.name}">
{/run-once}
{/let}
{/section}

The main problem I am having is that the offset dose not seem to be relative to the actual node I am viewing if that makes any sense, so if I was to navigate to "Products/mens_wear" the node name would still be "products" not "mens_wear".

I hope I have made this clear if not please let me know and I will try to be more descriptive.

Any help is very much appreciated thankyou for your time.

Pardon me while I burst into flames...

Nathan Kelly

Thursday 12 May 2005 5:05:34 pm

Oh one more thing, this code seems to do the same thing-

{let page_name=fetch( content, node, hash( node_id, $module_result.node_id ) )}

<body id="{$page_name.url_alias}">
{/let}

As I said I am not very familiar with the syntax so I really have no idea what the difference is with these 2 snippets.

cheers.

Pardon me while I burst into flames...

Xavier Dutoit

Friday 13 May 2005 12:50:24 am

Hi,

I'd suggest not to use the url_alias on the css (they can be modified by the user, but the node id

eg <div id="node_{$node.node_id}">

would produce id="node_2"

X+

http://www.sydesy.com

Nathan Kelly

Friday 13 May 2005 1:16:53 am

Thanks for your reply Xavier,

I had originally intended to use the node id but I was unsure if this would be the best way, and now that you mention it, it seems more logical as I hadn't considered the lack of persistence in the url_alias.

On that note just for my own clarification, is the node id persistent, that is will it ever change and if so what action would likely do so?

Cheers!

Pardon me while I burst into flames...

Roy Bøhmer

Friday 13 May 2005 5:32:00 am

The node-id is persistent, BUT an article can exist on several different places in the node-tree and therefore have several different node-ids.

A scenario could be that you
1)Publish an article with node-id=100.
2)Make a co-location of the same article, and now have node_id=100 AND node-id=200.
3)Then you make node-id=200 the primary node, and delete the node-id=100.
Now you only have node-id=200. If you use node-id in the url it will seems like the article has changed node-id.

Object-id on the other hand will be persistent.

Roy

Nathan Kelly

Sunday 15 May 2005 5:25:05 pm

Ok, thanks for that info Roy that clears up my main question for now but I'm sure I will have plenty more to come yet ;).

Cheers.

Pardon me while I burst into flames...