Empty tag

13 views
Skip to first unread message

Aaron

unread,
Aug 24, 2011, 11:28:38 PM8/24/11
to shpaml
I often want shpaml to output open/close tags with no content
(scripts, textareas, etc.). Is there a way to do this (or could there
be)? There are a few reasonable-looking ways of doing it that I
thought of, and probably many more:

>> textarea

textarea ||

Any of this look useful to others? Current solution is to write
straight html, which kinda defeats the point of using shpaml in the
first place.

Steve Howell

unread,
Aug 24, 2011, 11:46:58 PM8/24/11
to shp...@googlegroups.com
PASS in an indented block gets turned into an empty string, but it might not address all your use cases.

There was some recent discussion on this if you poke thru the archives a bit. I will try to get you a better answer if other folks don't chime in with a solution that fits your needs.

Steve Howell

unread,
Aug 25, 2011, 11:09:42 AM8/25/11
to shpaml
Have a look at this thread:

https://groups.google.com/group/shpaml/browse_thread/thread/c6f5c620922ae8cf

I think it more or less addresses your concerns, and it includes a
patch that implements a "||" syntax. If you need help applying the
patch, don't hesitate to ask for help.

James Robert

unread,
Aug 26, 2011, 9:13:34 AM8/26/11
to shp...@googlegroups.com
If you're using django-shpaml-template-loader, you'll get the 

div.my_class ||

syntax (becomes <div class="my_class"></div>) included

you can grab the included shpaml.py but you'll get some other django specific extensions as well. The commit log may help you understand the extension process though.

James

Steve Howell

unread,
Aug 26, 2011, 11:20:18 AM8/26/11
to shp...@googlegroups.com
This is probably the best solution.  It's highly unlikely that django extensions will cause any pain, and obviously if you happen to be using django, they will provide benefit.

James, where is the best place to download this?

From: James Robert <jia...@gmail.com>
To: shp...@googlegroups.com
Sent: Friday, August 26, 2011 6:13 AM
Subject: Re: Empty tag

James Robert

unread,
Aug 26, 2011, 5:23:24 PM8/26/11
to shp...@googlegroups.com
oops sorry:

The django extensions are not documented well yet, but this is how they work:

template tags begin with a % and variable insertions begin with an =

shpaml:
%block content
  .super-powers | are awesome
  %no children means no endblock
  you got that right

html output:
{% block content %}
  <div class="super-powers">are awesome</div>
  {% no children means no end block %}
  you got that right
{% endblock %}

shpaml
.super-hero
 .name |= user.username
 ul.powers
   %for power in powers
     =power.name

html output
<div class="super-hero">
  <div class="name">{{ user.username }}</div>
  <ul class="powers">
    {% for power in powers %}
      {{ power.name }}
    {% endfor %}
  </ul>
</div>


and of course this little guy:
shpaml:
.my-div ||

html:
<div class="my-div"></div>

Hope this helps :)

James
Reply all
Reply to author
Forward
0 new messages