What Is A Weblink

From MODx Wiki
Jump to: navigation, search

This article may require cleanup and/or formatting to meet MODx standards.
Feel free to log in and contribute to the modification of this article.

A weblink is a document of type "reference". It has no template, thus no TVs. It simply serves as a link that will be part of a generated menu.

The content of the weblink is just an URL. The parser doesn't even parse it; as soon as it sees that it is a "reference", it just uses the content as the argument for sendRedirect($url).

You can use an external URL for the content, or you can use a document Id to link to a document in your MODx document tree. (at least in the 0.9.5 beta version you can; in earlier version you must have the complete URL in the weblink's content) For example, you want a footer menu with links to a Terms of Use, a Privacy Policy, and stuff like that. But you also want a link to "Contact Us" there. Contact Us is one of your main pages, and is in the top-level of your tree to be displayed in your main menu. You would put those documents in one "utility pages" folder, probably unpublished so it won't show up in your main menu, and use that folder ID as the docId for the menu snippet. In that folder you would also put a weblink to your site's contact page. This way the menu will include a link to the contact page, even though that document is not in the folder.

Or, you could do it the other way around, have the Contact Us document in your unpublished "utility pages" folder, and put the weblink to it in your top-level so it will show in the main menu.

Originally a menu snippet would make the link to the weblink document itself, just as to any other MODx document, thus causing the page to be loaded by the parser, triggering the redirect. The latest version of Wayfinder uses the URL in the weblink's content directly, thus the URL in the menu is that of the desired page (internal to your MODx installation or to an external site) instead of using the URL to the weblink document and requiring the parser to redirect.

The most recent beta versions of MODx 0.9.5 include a modification to the core parser that allows the use of a document ID in the weblink.

Weblink-select.jpg

The parser will detect that the weblink's content is a number, and run it through makeUrl($id) before redirecting. A feature was also added to the weblink's editing page in the Manager that allows you to click on a little folder icon, then on a document in the Document Tree frame to select the desired document to link to. This works great with older menu snippets. However, the new Wayfinder uses the weblink's content to make its link, which totally breaks the use of a document's id!

This means that Wayfinder, and any other snippet that uses the content of the weblink doucment, must first run the value through $modx->makeUrl($id) before generating the link. Otherwise, the link will consist of "mydomain.com/6" (in the case where the content is 6) instead of the proper URL to the document being linked to (such as contact.html, or index.php?id=6).

This can be done by checking to see if the content value is_numeric():

  1. if($type == "reference") {
  2. if(is_numeric($content)) {
  3. $content = $modx->makeUrl($content);
  4. }
  5. ...
  6. ...
Personal tools