On Thu, 12 Jun 2014 13:09:29 GMT, Yiannis Tsirikoglou wrote:

Hello,

I can not figure out the following , maybe i miss something very obvious..

How can i insert html code in a diet file as a variable?

I have :

string[] errors ~= "<li>This is one error</li>";
errors ~= "<li>This is another error</li>";

Then:

string errorstring;
	foreach(er; errors){
		errorstring ~= er;
	}
	req.params["error"] = urlEncode(errorstring);
	showPage(req,res);

And then at showPage function:

if (auto er = "error" in req.params) info.errors = *er;

(Passing the string with in an info struct).

Then in my diet template i have:

- if(info.errors != "")
	ul
|#{vibe.textfilter.urlencode.urlDecode(info.errors)}

but it gives the string as text and not html.
i tried also: ul

|!= #{info.errors} or |!= "#{info.errors}"

but it gives <ul>#{info.errors}</ul>

Any ideas?

This should work:

ul!= info.errors
// or
u1
    != info.errors

or this:

ul
    |!{info.errors}

I would expect |!= #{info.errors} to result in a compiler error. I'll look into that.

And by the way does anybody have any advice about the best way to pass errors or notifications to different HTTP functions?
Hardcode them where they are displayed and pass error codes in queries?
Pass the error strings as parameters (but this doesn't work with res.redirect) or as query parameters in the url?

I usually pass them by parameter, but that indeed has the issue of not working well with redirects. The good thing is that this is supported by vibe.web.web, though, saving some boilerplate code:

@path("/")
void getIndex(string _error = null)
{
	render!("index.dt", _error);
}

@errorDisplay!getIndex
void postLogin(string username, string password)
{
	enforceHTTP(username.length > 0, HTTPStatus.forbidden,
		"User name must not be empty.");
	enforceHTTP(password == "secret", HTTPStatus.forbidden,
		"Invalid password.");
	m_loginUser = username;
	redirect("/profile");
}

Any exception will automatically cause getIndex to be called for rendering the error message. Later it's also planned to add direct parameter validation support that will call the error display function without any exceptions involved (for efficiency).