Page 1 of 1

Estimating entry length? Dynamically parameterizing plugins?

Posted: Tue Dec 09, 2008 10:12 pm
by Mekk
Well, my next idea: I would like to make my sidebars conditional, so their content depend on the entry length (so I build long sidebar along the long article, but cut it to the minimum along the short note). I am in particular looking for the following suggestions:

a) what could be the best method to estimate the entry length (while displaying it, from index.tpl)? It need not be very accurate, but it would be nice to know whether it is rather about 30 lines, or maybe about 300... Which variable should I access to avoid performance costs?

b) It would be nice if I could dynamically set the numer of items shown by serendipity_plugin_recententries and serendipity_plugin_comments. What could be the easiest way to achieve this? Note: I am currently rendering them calling explicite:

{serendipity_showPlugin id="..."}

in some .tpl. Ideal solution would be if I could just pass some params here and have them overwrite the configuration saved in the database...

Re: Estimating entry length? Dynamically parameterizing plug

Posted: Wed Dec 10, 2008 11:34 am
by garvinhicking
Hi!

a.) I would fetch the {$entry.body} and {$entry.extended} lengths. Note that you will not be able to calculate "lines", only "bytes" or "words". You can get this in index.tpl if you use the same loops like in entries.tpl (you need to iterate on $entries), but the array will only contain one entry, if {$view == 'entry'}. Of course another way is to use a custom event plugin that counts the length on the current entry by using one of the frontend_* event hooks and checking the $entry data immediately.

b.) That's not possible, because you cannot pass individual options on serendipity_showplugin. They always use the otpions you configured in the plugin. If you do not want that, you must create your own plugins,. or extend the current ones to be able to specify external parameters.

Regards,
Garvin

Posted: Wed Dec 10, 2008 11:58 am
by Mekk
Considering all this, I will probably go with a lazy route:

- flag short posts explicite using some custom property and testing for it in .tpls

- duplicate plugins (= create one history plugin with 10 entries and another with 5 entries) and just pick one of those depending on the setting above