RejectedSoftware Forums

Sign up

Why this template wont work?

req is passed to render:

void defaultHandler(HttpServerRequest req, HttpServerResponse res)
{

render!("test.dt", req)(res);

}

template:

extends layout

block content

h3 this is a form:
form(method='get')
    fieldset
        legend General
            label(for='username') Username:
                - auto v = req.params["username"];
                input( type='text', name='username', value='#{v}' )

result is:

<!DOCTYPE html>
<html lang="ru">

<head>
	<title>Info</title>
</head>
<body>
	<h1>test</h1>
	<img id="logo" src="/images/blyat.jpg" alt="Site logo"/>
	<h3>this is a form:</h3>
	<form method="get">
		<fieldset>
			<legend>General
				<label for="username">Username:

Re: Why this template wont work?

Sorry for the trouble. I checked in a change two days ago that seemed to be trivial (An option for Markdown to always escape '<' was added), but I forgot to pop the input element off a range in a loop, causing an infinite loop. Works now correctly (the preview suffered from the same bug).

As for the actual problem ;) - I'm pretty sure that req.params["username"] throws a RangeError there (maybe it should be req.form[]?). If you setLogLevel(LogLevel.Debug), you should get a stack trace on the console that gives more certainty.

Reformatted:

On Sat, 20 Oct 2012 02:36:31 +0200, denizzzka wrote:

req is passed to render:

void defaultHandler(HttpServerRequest req, HttpServerResponse res)
{
	render!("test.dt", req)(res);
}

template:

extends layout

block content
    h3 this is a form:
    form(method='get')
        fieldset
            legend General
                label(for='username') Username:
                    - auto v = req.params["username"];
                    input( type='text', name='username', value='#{v}' )

result is:

<!DOCTYPE html>
<html lang="ru">
	<head>
		<title>Info</title>
	</head>
	<body>
		<h1>test</h1>
		<img id="logo" src="/images/blyat.jpg" alt="Site logo"/>
		<h3>this is a form:</h3>
		<form method="get">
			<fieldset>
				<legend>General
					<label for="username">Username:

Re: Why this template wont work?

On Sat, 20 Oct 2012 06:17:54 GMT, Sönke Ludwig wrote:

As for the actual problem ;) - I'm pretty sure that req.params["username"] throws a RangeError there (maybe it should be req.form[]?). If you setLogLevel(LogLevel.Debug), you should get a stack trace on the console that gives more certainty.

Still does not work. Here is an example:

	void defaultHandler(HttpServerRequest req, HttpServerResponse res)
	{
		auto answ = conn.exec("select 12345");
		string cell = answ[0,0].as!PGtext;
		render!("test.dt", req, cell, answ)(res);
	}
extends layout

block content
    h3 this is a form:
    form(method='get')
        fieldset
            legend General
                label(for='username') Username:
                    input( type='text', name='username', value='vasya22' )
                    p #{cell} // done
                    p #{answ[0,0].as!PGtext} // error

cell variable passes to temlate parser, but answ[0,0].as!PGtext causes error:

Compiling diet template 'test.dt'...
test.dt(7): Error: undefined identifier PGtext, did you mean template text(T...)?
test.dt(7): Error: cannot resolve type for (*answ.opIndex(0LU,0LU)).as!(error)
test.dt(7): Error: template vibe.templ.diet.toString does not match any function template declaration<br>diet.d(912): Error: template vibe.templ.diet.toString(T) cannot deduce template function from argument types !()(error)

(answ[0,0].as!PGtext is actually a string type)

Apparently, I do not understand what types of variables supports templates parser. It would be convenient to show result of sql query in the template, but at the moment I can't.

Re: Why this template wont work?

(this is another case or not I don't know)

Re: Why this template wont work?

On Sun, 21 Oct 2012 02:21:13 GMT, denizzzka wrote:

(...)

Compiling diet template 'test.dt'...
test.dt(7): Error: undefined identifier PGtext, did you mean template text(T...)?
test.dt(7): Error: cannot resolve type for (*answ.opIndex(0LU,0LU)).as!(error)
test.dt(7): Error: template vibe.templ.diet.toString does not match any function template declaration<br>diet.d(912): Error: template vibe.templ.diet.toString(T) cannot deduce template function from argument types !()(error)

(answ[0,0].as!PGtext is actually a string type)

Apparently, I do not understand what types of variables supports templates parser. It would be convenient to show result of sql query in the template, but at the moment I can't.

For most external symbols, you need to add an appropriate import statement, as the compiled template file has it's own scope:

- import module.containing.pgtext;

Btw. (I know I need to change the documentation at some places) render!() is still suspicious for linker errors, or worse, memory corruption, because the corresponding DMD issue was never fully resolved (although marked as such). I still need to do a dustmite run at some day. But for now renderCompat!() is the safer choice.

Re: Why this template wont work?

On Sun, 21 Oct 2012 07:57:17 GMT, Sönke Ludwig wrote:

On Sun, 21 Oct 2012 02:21:13 GMT, denizzzka wrote:

(...)

Compiling diet template 'test.dt'...
test.dt(7): Error: undefined identifier PGtext, did you mean template text(T...)?
test.dt(7): Error: cannot resolve type for (*answ.opIndex(0LU,0LU)).as!(error)
test.dt(7): Error: template vibe.templ.diet.toString does not match any function template declaration<br>diet.d(912): Error: template vibe.templ.diet.toString(T) cannot deduce template function from argument types !()(error)

(answ[0,0].as!PGtext is actually a string type)

Apparently, I do not understand what types of variables supports templates parser. It would be convenient to show result of sql query in the template, but at the moment I can't.

For most external symbols, you need to add an appropriate import statement, as the compiled template file has it's own scope:

- import module.containing.pgtext;


Where? At the point where renderer called "import" already added (and assignment to a variable "cell" works well)

Btw. (I know I need to change the documentation at some places) render!() is still suspicious for linker errors, or worse, memory corruption, because the corresponding DMD issue was never fully resolved (although marked as such). I still need to do a dustmite run at some day. But for now renderCompat!() is the safer choice.

Re: Why this template wont work?

Where? At the point where renderer called "import" already added (and
assignment to a variable "cell" works well)

Think of the template like it is a separate module, it needs its own
list of imports. Just accessing the passed-in variables will work
regardless of imports, but as soon as something is to be referenced by
name, it must be imported first.

A possible place would be right at the beginning of the block:

extends layout

block content
   - import xyz;
   h3 this is a form:
   form(method='get')
       fieldset
           legend General
               label(for='username') Username:
                   input( type='text', name='username', value='vasya22' )
                   p #{cell} // done
                   p #{answ[0,0].as!PGtext} // error

Re: Why this template wont work?

On Sun, 21 Oct 2012 14:37:51 +0200, Sönke Ludwig wrote:

Where? At the point where renderer called "import" already added (and
assignment to a variable "cell" works well)

Think of the template like it is a separate module, it needs its own
list of imports. Just accessing the passed-in variables will work
regardless of imports, but as soon as something is to be referenced by
name, it must be imported first.

A possible place would be right at the beginning of the block:

extends layout

block content
   - import xyz;

Yes, its works! Thanks!