表达式引擎模板变量传递
我正在使用 Solspace 的用户和好友模块在 Expression Engine 2.3 中构建用户配置文件系统。它们工作得很好,但是我在传递嵌入变量方面遇到了非常困难的时期。
我有一个从每个模板调用的 .profile_head
模板。个人资料页面,好友页面,私人消息页面等。它构建了用户导航,显示头像,所有常见的用户内容。所有这些都基于通过 {segment_3}
传递的用户 ID。这允许我通过更改此段来显示不同用户的信息。
问题是这样做会使我的网址过于精确。我不能让用户访问 /users,他们必须访问 /users/profile/UID,或者最好的情况是出现错误页面或重定向到主页。
我尝试通过模板中的变量来解决这个问题:
{embed="/users/.profile_head" uid="{segment_3}"}
or......
{embed="/users/.profile_head" uid="{logged_in_member_id}"}
在 .profile_head
模板文件中,我可以很好地打印出 {embed:uid}
,但是当我尝试将它分配给任何东西(即循环或另一个模板),它会中断:
<!-- /users/.profile_head -->
{exp:friends:members member_id="{embed:uid}" dynamic="off" limit="1"}
or.....
{embed="users/.profile_column" uid="{embed:uid}"}
例如,如果将 {embed:uid}
设置为 {logged_in_member_id}
,我会得到以下结果错误:
Parse error: syntax error, unexpected T_LNUMBER in /var/www/system/expressionengine/libraries/Functions.php(656) : eval()'d code on line 9
这是第 9 行:
{if logged_in_member_id == "{embed:uid}"} <span class="this_is_you">This is you!</span>{/if}
我实在是束手无策了。我需要能够在模板中使用此配置文件标头,而不需要 URL 中的用户 ID 来处理用户消息传递和设置页面等内容。但我所做的一切似乎都毫无效果。
I'm building in Expression Engine 2.3 a user profile system using Solspace's User and Friends modules. They work fine, but I'm having an incredibly difficult time with passing embedded variables around.
I've got a .profile_head
template that's called from each template. The profile page, the friends page, the private messaging page, etc. It builds a user navigation, displays the avatar, all the common user stuff. All of this is based off of the user ID passed through {segment_3}
. This allows me to display a different user's info by changing this segment.
The problem is doing this makes my URLs far too precise. I can't have users going to /users, they have to go to /users/profile/UID or the best possible scenario is an error page or redirect to the home page.
I tried to solve this problem through variables in my template:
{embed="/users/.profile_head" uid="{segment_3}"}
or......
{embed="/users/.profile_head" uid="{logged_in_member_id}"}
In the .profile_head
template file, I can print out {embed:uid}
just fine, but when I try to assign it to anything (i.e. a loop or another template), it breaks:
<!-- /users/.profile_head -->
{exp:friends:members member_id="{embed:uid}" dynamic="off" limit="1"}
or.....
{embed="users/.profile_column" uid="{embed:uid}"}
For instance, if {embed:uid}
is set as {logged_in_member_id}
, I get the following error:
Parse error: syntax error, unexpected T_LNUMBER in /var/www/system/expressionengine/libraries/Functions.php(656) : eval()'d code on line 9
This is line 9:
{if logged_in_member_id == "{embed:uid}"} <span class="this_is_you">This is you!</span>{/if}
I really am at my wits end. I need to be able to use this profile header in templates without requiring a user id in the URL for things like the user messaging and settings pages. But nothing I try seems to be working in the least.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信
{logged_in_member_id}
是一个后期解析的变量,这意味着它在某些标记处理时可能不可用 - 因此它被传递正如字面上的{logged_in_member_id}
。尝试改用
CURRENT_USER
常量。I believe that
{logged_in_member_id}
is a late-parsed variable, which means it may not be available in some of your tags at the point they're processed - hence it's passed as literally{logged_in_member_id}
.Try using the
CURRENT_USER
constant instead.