Hi,
I’ve had a lot of requests for wild menu scenarios, including redundant menu links.
All I did was do weblinks to existing documents, so for example if my "About Us" is document 22, my weblink just looks like "[[~22]]" I do this to stick an extra link into, say, the footer menu group of documents although "About Us" is elsewhere in the tree.
The only problem in that scenario is that the "real" About Us link will show as "active" in the main menu, but the footer link won’t, but that hasn’t been a problem to my clients. Maybe that’s what you’re looking for, though, and my method won’t do that.
Good luck, D
To solve this issue I used two addon’s: If and getResourceField.
This will give the weblink menu item a class of "current" when the weblink content is equal to the current page’s relative URL.
&rowTpl chunk
<li[[+wf.id]] class="[[+wf.classnames]] [[!If? &subject=`[[!getResourceField? &id=`[[+wf.docid]]` &field=`content`]]` &operator=`==` &operand=`[[~[[*id]]]]` &then=` current` &else=``]]"><a href="[[+wf.link]]" title="[[+wf.title]]" [[+wf.attributes]]>[[+wf.linktext]]</a>[[+wf.wrapper]]</li>
This is achieved by using the If snippet to check the content field of the weblink, using getResourceField, is equal to the current documents URL. See If snippet call below:
[[!If?
&subject=`[[!getResourceField?
&id=`[[+wf.docid]]`
&field=`content`]]`
&operator=`==`
&operand=`[[~[[*id]]]]`
&then=` current`
&else=``]]
*note: this assumes the content of the weblink is regular modx hyperlink
e.g. [[~16]] (16 is the document my weblink is linking to)
Not the most elegant solution but it works and working is half the battle
Environment:
modx: rev 2.0.8-pl
localhost: Apache/2.0.63 (Unix) PHP/5.2.11 DAV/2, MySQL client version: 5.1.37
No trouble, it’s actually pretty cool to be able to help.
It’s strange that this behavior for weblinks is not built into modx by default... I mean, it does seem like a pretty common use case scenario to have weblinks in menus that point to other modx documents. Maybe it’s a Wayfinder thing? IDK
Cheers,
Aaron
Environment:
modx: rev 2.0.8-pl
localhost: Apache/2.0.63 (Unix) PHP/5.2.11 DAV/2, MySQL client version: 5.1.37
In EVO I added the following logic to the part of wayfinder.inc.php that runs through and decides which TPL chunk to use for display (showing lines 157-158, added 159-160):
elseif ($resource['id'] == $modx->documentObject['id'] && $this->_templates['hereTpl']) {
$usedTemplate = 'hereTpl';
} elseif ($resource['description'] == $modx->documentObject['id'] && $this->_templates['hereTpl']) { //added for weblinks here
$usedTemplate = 'hereTpl';
This worked really well, inside of the weblink, I made sure to make the ’description’ field have the same number as the page it is referencing, and voila! it works. This should be doable in Revo, but it may be hard to find where the logic is, and it may need some syntax translating to upgrade it to Revo.
"Great spirits have always encountered violent opposition from mediocre minds." -Albert Einstein
Quote from: kp52 at Apr 07, 2011, 06:43 AM
The above is just what I was looking for for an Evo site. I find it works using the content field as well (not obvious in the manager, but I have found the content is the same as the Weblink field when switching back and forth between Web Page and Weblink resource types). So there’s no need to duplicate the data in the Description.
} elseif ($resource['id'] == $modx->documentObject['id'] && $this->_templates['hereTpl']) {
$usedTemplate = 'hereTpl';
} elseif ($resource['content'] == $modx->documentObject['id'] && $this->_templates['hereTpl']) { //added for weblinks here
$usedTemplate = 'hereTpl';
KP
Do you mean that by changing the code like that, you don’t have to type in the resource ID into the description field?
"Great spirits have always encountered violent opposition from mediocre minds." -Albert Einstein
That’s AWESOME. Before I had the following code in there, not realizing it would populate it for me:
Thanks a bunch!
"Great spirits have always encountered violent opposition from mediocre minds." -Albert Einstein