webdevRefinery Forum: Hydrogen Templates for Front-End Developers - webdevRefinery Forum

Jump to content

Hydrogen what, now?

Hydrogen is an open-source PHP toolkit that focuses on speed, with the goal of making your webapps faster if they're built on Hydrogen then they would be if written from scratch. It was created to be portable: applications written on Hydrogen should be able to be installed on many different types of servers with different database types or cache engines without changing any code or doing any extra programming work.

This forum contains the official tutorials for Hydrogen, until Hydrogen reaches version 1.0 and they move to HydrogenPHP.com. Please feel free to comment on them if you need help understanding them, or contribute your own tutorials that might later be published on the official site!
  • 8 Pages +
  • « First
  • 6
  • 7
  • 8
  • You cannot start a new topic
  • You cannot reply to this topic

User is offline Cyril 

  • Group: Members
  • Posts: 2544
  • Joined: 03-August 10
  • Expertise:HTML,CSS,PHP,Javascript,Graphics

Posted 31 December 2011 - 09:07 AM (#141)

Here's what I'm using;
{% if !exists hideAbout %}
{# some html with a link to an about page goes here #}
{% endif %}


Now, that works fine. However, if I change it to:
{% if not exists hideAbout %}
{# some html with a link to an about page goes here #}
{% endif %}


El error appears.
Fatal error: Uncaught exception 'hydrogen\view\engines\hydrogen\exceptions\TemplateSyntaxException' with message 'Misplaced variable 't' in expression: 'not exists hideLogo'' in /Users/cyrilmengin/Sites/Made In Europe/MadeInEurope.com/lib/hydrogen/view/engines/hydrogen/ExpressionParser.php:282 Stack trace: #0 /Users/cyrilmengin/Sites/Made In Europe/MadeInEurope.com/lib/hydrogen/view/engines/hydrogen/nodes/IfNode.php(29): hydrogen\view\engines\hydrogen\ExpressionParser::exprToPHP('not exists hide...', Object(hydrogen\view\engines\hydrogen\PHPFile), 'layouts/base') #1 /Users/cyrilmengin/Sites/Made In Europe/MadeInEurope.com/lib/hydrogen/view/engines/hydrogen/NodeArray.php(36): hydrogen\view\engines\hydrogen\nodes\IfNode->render(Object(hydrogen\view\engines\hydrogen\PHPFile)) #2 /Users/cyrilmengin/Sites/Made In Europe/MadeInEurope.com/lib/hydrogen/view/engines/hydrogen/HydrogenEngine.php(197): hydrogen\view\engines\hydrogen\NodeArray->render() #3 /Users/cyrilmengin/Sites/Made In Europe/MadeInEurope.com/lib/hydrogen/view/View in /Users/cyrilmengin/Sites/Made In Europe/MadeInEurope.com/lib/hydrogen/view/engines/hydrogen/ExpressionParser.php on line 282


website :: github :: twitter :: dribbble :: forrst
html, css, php, javascript, graphics
0


User is offline Marked 

  • Group: Members
  • Posts: 111
  • Joined: 21-May 10
  • LocationChch, NZ
  • Expertise:HTML,CSS,PHP,SQL

Posted 31 January 2012 - 09:00 PM (#142)

I think I found an error? The date function isn't working for me with timestamps:
This:
Posted Image
Outputs this:
Posted Image
0


User is offline inkjetcanvas 

  • Group: Moderators
  • Posts: 74
  • Joined: 08-April 10
  • LocationPhiladelphia, PA
  • Expertise:HTML,CSS,Javascript,Graphics

Posted 17 February 2012 - 10:16 AM (#143)

Love this! I use Django's Template (the .py version) for my day job and this for our side projects and really enjoy working in it.

One request that I'd love is the addition of a {% verbatim %} block to escape my handlebars.js templates. This guy did it for the .py version, found here:
http://tothinkornott...-js-with-django

and his code here:
https://gist.github.com/629508

This way I can do stuff like:
<div class="{{ some.hydrogen.var }}">
{% verbatim %}
<p>{{ my.handlebars.var }}</p>
{% endverbatim %}
</div>



Since I'm a front-ender I'll probably look to build a JS-side adaptation to handlebars before I try to hack on some PhP, but it would make me very happyface to see this as a part of hydrogen's templates. :D
kristi.theresnobox.net | inkjetcanvas.us

"I'm just a dweeb invited to the cool kid's party, hoping she doesn't get found out before the beer is gone."
0


User is offline Kyek 

  • Founder of wdR
  • Group: Administrators
  • Posts: 5078
  • Joined: 20-February 10
  • LocationPhiladelphia, PA, USA
  • Expertise:HTML,CSS,PHP,Java,Javascript,Node.js,SQL

Posted 17 February 2012 - 10:27 AM (#144)

Interesting! That would be a good addition -- adding
{% templatetag openvariable %}
and
{% templatetag closevariable %}
Everywhere would do it, but would totally suck. I'll put this on my list :)
0


User is offline derTechniker 

  • BadBoy™
  • Group: Members
  • Posts: 1210
  • Joined: 06-July 10
  • LocationAustria
  • Expertise:HTML,CSS,PHP,Javascript,SQL

Posted 24 February 2012 - 05:55 PM (#145)

View PostKyek, on 31 December 2011 - 08:15 AM, said:

So when I first read this, I was all, "well that's strange, I didm't change anything and my tests for the "not" keyword still work. Then we started using Hydrogen at work and one of my devs started writing templates, and he had no issue with 'not'. Can I see the snippet where it's not working?



had the same issue a month ago when i tried it, do not have the codeblock anymore, but it was a simple 'not' statement
0


User is offline Jawsh 

  • Group: Members
  • Posts: 3
  • Joined: 18-March 12

Posted 18 March 2012 - 11:47 AM (#146)

Hey, I'm wondering if the Hydrogen View engine can do something similar to the Twig global feature, or possible to achieve this? http://twig.sensiola...ed.html#globals
0


User is offline gibbonweb 

  • 兄ヨハネス
  • Group: Members
  • Posts: 2061
  • Joined: 23-June 10
  • LocationMunich(DE)
  • Expertise:HTML,CSS,PHP,Javascript,Python,SQL,Graphics

Posted 18 March 2012 - 01:22 PM (#147)

View PostJawsh, on 18 March 2012 - 11:47 AM, said:

Hey, I'm wondering if the Hydrogen View engine can do something similar to the Twig global feature, or possible to achieve this? http://twig.sensiola...ed.html#globals

Of course! They are not called globals though, but are just variables in an array called 'context' you'd pass into the view. The twig example would look like this in Hydrogen:

<?php
$mycontext = array( "text" => new Text() );
View::load('text', $mycontext);

// or, of course, just in one statement:

View::load('text', array(
				'text' => new Text()
			));


Passing parameters to template variables as in
{{text.lipsum(40)}}
(twig) is not possible as far as I know (but I might just have forgotten it - didn't use Hydrogen in a long time due to lack of time :( ).

In the example, lipsum(40) will give you a Lorem ipsum text of length 40 (words?) - THAT you can achieve with the excerpt filter
{{text.lipsum|except:5:"w":"."}}
I wrote just for you a few months ago (to be fair, I wrote a horrid, strangely formatted draft for it and Kyek replaced almost every single line of it when he merged my code xD).
0


User is offline Jawsh 

  • Group: Members
  • Posts: 3
  • Joined: 18-March 12

Posted 25 March 2012 - 05:00 AM (#148)

Can anyone provide me on any more details on how I can achieve the twig global function in Hydrogen?
0


User is offline Kyek 

  • Founder of wdR
  • Group: Administrators
  • Posts: 5078
  • Joined: 20-February 10
  • LocationPhiladelphia, PA, USA
  • Expertise:HTML,CSS,PHP,Java,Javascript,Node.js,SQL

Posted 25 March 2012 - 08:27 AM (#149)

Hey Jawish-- Gibbonweb's answer should be what you need :). The only difference between globals in Twig and globals in Hydrogen is that Hydrogen just calls them variables.

Just do this...
View::setVar('myVar', new SomeObj());
// or...
View::setVar('myVar', 4);

And then whenever you get around to loading a view, that variable will be there. Or, as Gibbonweb said, you can just pass those variables in with the View::load() call for the same effect.
0


User is offline Jawsh 

  • Group: Members
  • Posts: 3
  • Joined: 18-March 12

Posted 25 March 2012 - 08:57 AM (#150)

Thanks, Kayak. (You misspell my name, I'll misspell yours. :)) :lol:
0


User is offline Kyek 

  • Founder of wdR
  • Group: Administrators
  • Posts: 5078
  • Joined: 20-February 10
  • LocationPhiladelphia, PA, USA
  • Expertise:HTML,CSS,PHP,Java,Javascript,Node.js,SQL

Posted 25 March 2012 - 01:30 PM (#151)

Ha -- apologies, Jawsh xD
0


User is offline Hamador 

  • Group: Members
  • Posts: 140
  • Joined: 21-March 10
  • LocationLas Vegas

Posted 08 October 2012 - 11:26 AM (#152)

I just started playing with the templates and I'm getting an error
Misplaced variable '&&' in expression: 'employees and admin = 1'


My code is :
{% if employees and admin = 1 %}

if I do
{% if employees %}{% if admin = 1 %}

it works just fine, is there something I'm missing on how 'and' is supposed to be used?
[DOT DOT DOT]


Posted Image
0


User is offline Kyek 

  • Founder of wdR
  • Group: Administrators
  • Posts: 5078
  • Joined: 20-February 10
  • LocationPhiladelphia, PA, USA
  • Expertise:HTML,CSS,PHP,Java,Javascript,Node.js,SQL

Posted 08 October 2012 - 12:39 PM (#153)

To be honest, I think that the bug isn't that
{% if employees and admin = 1 %}
doesn't work.. it's that
{% if employees %}
DOES work xD.

I never built out full support for the "if VARNAME" syntax -- you have to say something like "if exists varname" or "if varname = 1". So the following would work:
{% if exists employees and admin = 1 %}
<!-- or... -->
{% if employees = 1 and admin = 1 %}


But apparently the only reason
{% if employees %}
works right now is because the expression ends, and Hydrogen isn't checking to make sure the expression was completed before it renders it to PHP. It's just by sheer stroke of luck that it produces valid PHP when it renders that :)

Good catch!
0


User is offline Hamador 

  • Group: Members
  • Posts: 140
  • Joined: 21-March 10
  • LocationLas Vegas

Posted 08 October 2012 - 01:17 PM (#154)

From the overview I took to understand
{% if employees %}
would evaluate a true/false, the var employee is always set to either content or false.

I also attempted
{% if user.name = "hamador" and admin = 1 %}
with the same error.
[DOT DOT DOT]


Posted Image
0


User is offline Kyek 

  • Founder of wdR
  • Group: Administrators
  • Posts: 5078
  • Joined: 20-February 10
  • LocationPhiladelphia, PA, USA
  • Expertise:HTML,CSS,PHP,Java,Javascript,Node.js,SQL

Posted 08 October 2012 - 01:42 PM (#155)

Oh well damn. Definitely a bug then -- I'll check it out asap!
0


Share this topic:


  • 8 Pages +
  • « First
  • 6
  • 7
  • 8
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users


Enter your sign in name and password


Sign in options
  Or sign in with these services