Re: @set is deprecated, but doesn't seem to have a replacement

15 views
Skip to first unread message

green

unread,
Apr 28, 2014, 5:42:03 PM4/28/14
to Harshdeep S Jawanda, Rythm Engine
Hi Hashdeep,

This is a good question. I guess my answer is @set shouldn't be deprecated. They are necessary to pass run-time updates to parent template. Actually what you need is just need to use @set(), for any place you want to use @get("foo"), you can use @foo if you have declared "foo" as render argument in your parent template. If you haven't declared foo as render args using @args directive, then you still need to use @get("foo") to pick it up

I have just pushed an new 1.0.1-SNAPSHOT so that you can even use @set() to set the render args for "this" template, not just parent template. Thus you can do something like:

@args String title

@if(a) {
@set(title: "A")
} else {
@set(title: "B")
}

<h1>@title</h1>

Although you can do the same thing this way:

@args String title

@{
title = a ? "A" : "B"
}

<h1>@title</h1>

However the second way won't pass the new title to the parent template, while the first allows you to use @title to get anything you passed via @set(title: ...)


Regards,
Green


On Tue, Apr 29, 2014 at 12:28 AM, Harshdeep S Jawanda <hsja...@gmail.com> wrote:
Hi,

So my question basically boils down to: how do I dynamically (i.e., at run-time) set variables in the base template from code in the extending templates?

Let's say I am making blogging software. The home page can have a fixed title, but when I click on a blog post and go to the page corresponding to that page, I need the title of the resulting page to be the title of that blog post.

This can only happen if the title variable contained/defined/declared in the base template can be set at run-time by code in the extending template that corresponds to showing a single blog post. So far as I know, @set is the only way to do it, but it is deprecated.

So what does one do when @set goes away?

--
Regards,
Harshdeep S Jawanda

Harshdeep S Jawanda

unread,
Apr 29, 2014, 9:41:37 AM4/29/14
to green, Rythm Engine
Thanks for your reply.

What I am currently doing now (and which works):

In base template:
@args String title
...
<title>@title</title>
In extending template:
@extends(base.tmpl)

@set("title": (null != prod) ? prod.getName() : "No such product")

Other than the deprecation warnings, this works fine. So will the deprecation warnings for @set be removed in future versions of Rythm?

green

unread,
Apr 29, 2014, 9:50:46 AM4/29/14
to Rythm Engine
Yes, it is removed from the current 1.0.1-SNAPSHOT. You can run mvn --update-snapshots to update your rythm version
Reply all
Reply to author
Forward
0 new messages