如何获取符号链接在符号链接模板中指向的 id?

发布于 2024-10-25 12:49:57 字数 218 浏览 6 评论 0原文

这很难解释......

在 modX Revolution 中,我试图在模板中获取符号链接的“Symlink”字段,以便在代码片段中使用它(符号链接指向的 id)。

当我将鼠标悬停在该字段上时的建议是 [[*content]],但是在使用它时,我得到了我用符号链接指向的页面的实际内容。

有什么建议吗?该文档没有帮助,我已经用谷歌搜索了一个小时了。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

老旧海报 2024-11-01 12:49:57

AFAIK,这是符号链接的预期行为。

我刚刚在我的测试服务器上启动了一个小测试,结果如下:

getResource(从包管理安装它)没有返回符号链接:

如果 6 是指向 id 为 10 的页面的符号链接的 id:

[[!获取资源? &resources=6]]

将返回:

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] => 
)

请注意,内容键为空。

MODx 论坛上的用户 lkossis 建议另一种方法:使用片段来获取 [[*content]] 值。

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

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

在您的模板中:

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

归功于 MODx 论坛上的 lkossis。
http://modxcms.com/forums/index.php/topic ,61784.msg351101.html#msg351101

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文