Categories > TinyButStrong general >

Easy one? Hide a block that uses absolute syntax.

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Nick_UK
Date: 2009-08-19
Time: 02:16

Easy one? Hide a block that uses absolute syntax.

Hello,

I'm using blocks to hide bits of template markup that won't be needed within certain pages. For example:-

[onload;block=div;when [var.category]!=0]

Cool, but two things:-

1. I have to admit, I quite like absolute block syntax, I find it a bit easier to read.

2. The above example works when I put it within a pair of HTML tags. What about if I want to hide a self-closing tag? For example:-

<img src="image.png" />

Can I use absolute syntax to hide blocks of code?

I hope I'm not barking up the wrong tree with this request. I've only been experimenting with TBS for an hour or so (good experience so far).

Cheers,

Nick

... and one other thing. How would I add a comment to a template?
By: TomH
Date: 2009-08-19
Time: 04:17

Re: Easy one? Hide a block that uses absolute syntax.

Welcome first of all,

ABout your question...
From the Manual
Special marks:
block=_     Define a block on the text line which holds the TBS tag. A text line always ends with a new-line char. New lines for Windows, Linux and Mac are supported. This feature is very useful for a template with text contents for example.
block=tag/     By adding character / at the end of the tag's name, TBS won't retrieve the closing tag. The block will be defined on the single opening HTML tag which contains the TBS tag. This can be useful to multiply an image for example.

From my soapbox...
Since you're new, let me recommend three things to make your live in TBS land enormously more rewarding - and easier...
(1) read the manual once - you won't remember every detail, but you'll remember that you saw it somewhere ;)
(2)  work thru every one of the "Examples" - adapting them to work on your own server. Skrol29 has done a great job with them as they cover 90% of everything you need to know about properly coding TBS
(3) read the "5 Golden Rules" show at
http://www.tinybutstrong.com/support.php#goldenrules

After that just come here whenever you get stuck -- and show your actual code (cut & paste) not pseudo code. There's lots of help here on the forum - but none of us are can help fix problems if the problem isn't clearly specified.

Cheers, you've found the best damn template engine - by far,
TomH


By: Nick_UK
Date: 2009-08-22
Time: 00:55

Re: Easy one? Hide a block that uses absolute syntax.

Thanks very much for the reply, it's good to know that there's an active community behind this project.

Right, don't worry, I've read the manual a couple of times; though I'm still having trouble finding what I'm after.

Cut and paste? Sure, here is the solution that uses the syntax that I'm not so keen on. It's in the <head> of my HTML template.

    <script type="text/javascript">
[onload;block=script;when [var.category]!=0]
    $(document).ready(function() {
        $("#category-order-table").tableDnD({
               onDragClass: "mydragclass",
                onDrop: function(table, row) {
                        var rows = table.tBodies[0].rows;
                        var debugStr = "Row dropped was "+row.id+". New order: ";
                for (var i=0; i<rows.length; i++) {
                    debugStr += rows[i].id+" ";
                }
            },
        });
    });
    </script>

... I hope that renders okay, I won't find out until it's too late.

Basically, I've got a number of pages that use very similar markup; though some of the pages use additional Javascript.

I figure that a reasonable strategy is to include all of the Javascript in the template, and then hide the bits that I don't need when pages are created. This way the created pages are kept clean, while the template on which they're based contains everything that's needed - it will be straightforward to maintain a single file. Good? That's where this comes in...

<script>[onload;block=script;when [var.category]!=0]</script>

... Placing the TBL tag in between the two script tags causes the script tags and their children to be removed from the created page, unless the PHP variable $category == 0. Great, yes indeed, but I'd quite like to achieve the same effect using the following syntax...

[thestuffiwanttohide;block=begin]
     In here is the markup that I want to hide.
[thestuffiwanttohide;block=end]

Why do I want to do this? Well, because I'm a simple creature and would find it easier to read TBL tags that are consistent with the markup... I like read down through documents.

With the "Simple syntax" solution I read into an HTML tag, encounter the TBL tag, and then I have to read backward in order to identify what's being effected. To me (and perhaps only me) a template would be a bit easier to follow if the markup that I want to hide were contained within a pair of TBL tags.

Make sense?.. Probably not. :)

Also, something I've spotted in the docs; 'Explicit' and 'Absolute' syntax are the same, are they not? I'm reluctant to trust my judgement, what with my being new to TBL, but it seems to me that the documentation could be tidied up a little bit?

As for adding comments to my templates, I'll leave that for another day.

Thanks again,
By: Nick_UK
Date: 2009-08-22
Time: 01:16

Re: Easy one? Hide a block that uses absolute syntax.

Righto,

This pair seem to have done the trick...
[onload;block=script;block=begin;when [var.category]!=0]
The markup that I want to hide goes in here.
[onload;block=script;block=end]

...which was actually quite easy to put together when I stepped away from my desk for ten minutes (it helps that I'm not working away.

Any thoughts?

... now all I need to do is to be able to add comments to my template (I'd like to make a note of where certain scripts are used), and I'll cease the ridiculous questions. Mind you, I'm now unsure that good practice to add comments to the templates.
By: Nick_UK
Date: 2009-08-22
Time: 10:56

Re: Easy one? Hide a block that uses absolute syntax.

So I've just qualified my idiocy...

[onload;block=begin;when [var.category]!=0]
This is obvious, now that I think about it.
[onload;block=end]

I hang my head in shame.
By: Nick_UK
Date: 2009-08-22
Time: 14:05

Re: Easy one? Hide a block that uses absolute syntax.

A final, final note...

Much of my confusion stems from general theory, the problems I've experienced with TBL syntax are only due to my reluctance to use the first solution to the conditional display problem that I found.

My (extremely simple) understanding is that a template should be just that, it shouldn't contain any logic for altering how an outputted page should be displayed. No? With this in mind, isn't it wrong to include conditional statements in a template?

The 'conditional display' example at TBL seems to have mixed a bit of logic in with the template, rather than simply defining blocks of HTML and working with them elsewhere. Am I getting the wrong end of the stick?

Over and out.
By: TomH
Date: 2009-08-22
Time: 17:24

Re: Easy one? Hide a block that uses absolute syntax.

Good job fixing your own stuff!! ;)

As for 'conditional display' as a philosophical issue... IMHO It's a matter of where to place the 'conditions' - in the PHP side or the Template side. I decide based on what it is that's being in/excluded. If I'm flagging something that should be accessible to the page stylists then I don't worry that there's a bit of logic in the template page - as otherwise the stylists wouldn't be able to modify the look/feel of the page.
I don't want ANY of the generated HTML to come from my PHP code.

When I need content control based on 'event functions' and as part of that I need to generate a bit of HTML - I try to specify a class for that bit and add a comment line to the HTML templete to alert the stylists.

HTH,
TomH