开发者

How to get the id a symlink is pointing at in the symlink's template?

This is pretty hard to explain...

In modX Revolution, I'm trying to get the symlink's "Symlink" field in the template to use it in a snippet (the id the symlink is pointing at).

The suggestion when I mouseover that field is [[*content]], but when using that I get the actual content of the page I'm pointing at with the symlink.

开发者_开发技巧

Any suggestions? The documentation doesn't help, and I've been google-ing it for an hour now.


AFAIK, this is the expected behavior for a symlink.

I just fired up a little test on my testing server and here is the result:

getResource (install it from Package Management) returns no symlink:

If 6 is the id of the symlink pointing to a page with the id of 10:

[[!getResources? &resources=6]]

will return:

Array (
    [id] => 6
    [type] => document
    [contentType] => text/html
    [pagetitle] => My Symlink
    [alias] => my-symlink
    [link_attributes] => 
    [published] => 1
    [parent] => 0
    [isfolder] => 
    [introtext] => 
    [content] => 
    [richtext] => 
    [template] => 1
    [menuindex] => 2
    [searchable] => 1
    [cacheable] => 1
    [createdby] => 1
    [createdon] => 2011-03-25 09:43:31
    [editedby] => 1
    [editedon] => 2011-03-25 09:57:30
    [deleted] => 
    [deletedon] => 0
    [deletedby] => 0
    [publishedon] => 2011-03-25 09:43:00
    [publishedby] => 1
    [menutitle] => 
)

Please note that the content key is empty.

User lkossis on MODx Forums suggests another approach: using a snippet to get the [[*content]] value.

$id= isset($id) && intval($id) ? intval($id) : $modx->resource->get('id');
$field = isset($field) ? $field : 'id';

$thisDocument=$modx->getDocument($id);
return $thisDocument[$field];

And in your template:

[[!getDocumentField? &field=`content`]]

The credit goes to lkossis on MODx Forums. http://modxcms.com/forums/index.php/topic,61784.msg351101.html#msg351101

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜