How do I dynamicly tell a "boucle" what to do?

Hi!

Is it possible to pass a variable to the loop? I want to do something like
this:

<?php
  $sortBy = titre;
?>

<BOUCLE_articles(ARTICLES) {par $sortBy}>
          #TITRE<br>
</BOUCLE_articles>

The problem is that I can't create the boucle in PHP (spip complains about
wrong boucle syntax).

So... I have the information in a variable. Is it possible to pass it to the
spip loop somehow?

/Mattias

Spip doesn't recognise filters this way. you have to define them in the mes_fonctions.php3 file before you can use them in your boucles.
See the article at: http://www.spip.net/ecrire/articles.php3?id_article=2055 on the subject.

George

Mattias Nyrell wrote:

Hi!

Is it possible to pass a variable to the loop? I want to do something like this:

<?php
$sortBy = titre;
?>

<BOUCLE_articles(ARTICLES) {par $sortBy}>
         #TITRE<br>
</BOUCLE_articles>

The problem is that I can't create the boucle in PHP (spip complains about wrong boucle syntax).

So... I have the information in a variable. Is it possible to pass it to the spip loop somehow?

/Mattias

_______________________________________________
spip-en@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-en

I couldnt access that page, it asks for a login...

/Mattias

On Monday 29 September 2003 11.45, George Kandalaft wrote:

Spip doesn't recognise filters this way. you have to define them in the
mes_fonctions.php3 file before you can use them in your boucles.
See the article at:
http://www.spip.net/ecrire/articles.php3?id_article=2055 on the subject.

George

Mattias Nyrell wrote:
>Hi!
>
>Is it possible to pass a variable to the loop? I want to do something like
>this:
>
><?php
> $sortBy = titre;
>?>
>
><BOUCLE_articles(ARTICLES) {par $sortBy}>
> #TITRE<br>
></BOUCLE_articles>
>
>The problem is that I can't create the boucle in PHP (spip complains about
>wrong boucle syntax).
>
>So... I have the information in a variable. Is it possible to pass it to
> the spip loop somehow?
>
>/Mattias
>
>_______________________________________________
>spip-en@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-en

_______________________________________________
spip-en@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-en

Try SPIP's tags: the syntax - SPIP

Simon

Mattias Nyrell wrote:

I couldnt access that page, it asks for a login...

/Mattias

On Monday 29 September 2003 11.45, George Kandalaft wrote:

Spip doesn't recognise filters this way. you have to define them in the
mes_fonctions.php3 file before you can use them in your boucles.
See the article at:
http://www.spip.net/ecrire/articles.php3?id_article=2055 on the subject.

George

Mattias Nyrell wrote:
   

Hi!

Is it possible to pass a variable to the loop? I want to do something like
this:

<?php
$sortBy = titre;
?>

<BOUCLE_articles(ARTICLES) {par $sortBy}>
        #TITRE<br>
</BOUCLE_articles>

The problem is that I can't create the boucle in PHP (spip complains about
wrong boucle syntax).

So... I have the information in a variable. Is it possible to pass it to
the spip loop somehow?

/Mattias

_______________________________________________
spip-en@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-en
     

_______________________________________________
spip-en@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-en
   
_______________________________________________
spip-en@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-en

Le lun 29/09/2003 à 14:23, Mattias Nyrell a écrit :

I couldnt access that page, it asks for a login...

Of course, it's :

:wink:

> Spip doesn't recognise filters this way. you have to define them in the
> mes_fonctions.php3 file before you can use them in your boucles.
> See the article at:
> http://www.spip.net/ecrire/articles.php3?id_article=2055 on the subject.
>
> George

ok, I have read that, but it's not that I wan't to apply a filter to the
things I get from the DB, rather I wan't to tell spip what to get from the DB
in the first place.

My site will have many articles on different subjects, and my idea is to allow
the visitor to to do things like show all articles, show all authors and
their articles, show all articles with a certain keyword, sort by title, sort
by authorname, sort by date etc etc.

I can't use a different HTML/SPIP template for each of these variants. It
wouldn't be very manageable...

Any ideas on how I could design a SPIP site with these features?

/Mattias

On Monday 29 September 2003 14.35, Simon Schneebeli wrote:

Try SPIP's tags: the syntax - SPIP

Simon

Mattias Nyrell wrote:
>I couldnt access that page, it asks for a login...
>
>/Mattias
>
>On Monday 29 September 2003 11.45, George Kandalaft wrote:
>>Spip doesn't recognise filters this way. you have to define them in the
>>mes_fonctions.php3 file before you can use them in your boucles.
>>See the article at:
>>http://www.spip.net/ecrire/articles.php3?id_article=2055 on the subject.
>>
>>George
>>
>>Mattias Nyrell wrote:
>>>Hi!
>>>
>>>Is it possible to pass a variable to the loop? I want to do something
>>> like this:
>>>
>>><?php
>>> $sortBy = titre;
>>>?>
>>>
>>><BOUCLE_articles(ARTICLES) {par $sortBy}>
>>> #TITRE<br>
>>></BOUCLE_articles>
>>>
>>>The problem is that I can't create the boucle in PHP (spip complains
>>> about wrong boucle syntax).
>>>
>>>So... I have the information in a variable. Is it possible to pass it to
>>>the spip loop somehow?
>>>
>>>/Mattias
>>>
>>>_______________________________________________
>>>spip-en@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-en
>>
>>_______________________________________________
>>spip-en@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-en
>
>_______________________________________________
>spip-en@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-en

_______________________________________________
spip-en@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-en

Le lun 29/09/2003 à 15:02, Mattias Nyrell a écrit :

ok, I have read that, but it's not that I wan't to apply a filter to the
things I get from the DB, rather I wan't to tell spip what to get from the DB
in the first place.

My site will have many articles on different subjects, and my idea is to allow
the visitor to to do things like show all articles, show all authors and
their articles, show all articles with a certain keyword, sort by title, sort
by authorname, sort by date etc etc.

I can't use a different HTML/SPIP template for each of these variants. It
wouldn't be very manageable...

But it's the only solution (except writing your own PHP/MySQL code, but
I guess you don't really want that). SPIP's loops are interpreted before
any PHP code, and there is no workaround I know of.

If you choose to write different templates for the different variants,
you can still <INCLUDE> some common parts so that the task is a little
easier for you. You can also do some clever loop nesting with
conditional codes (<//B_boucle>) so as to trigger different loops
depending on the URL parameters.

Hope that helps.

Antoine.

From what you are saying, all you need are the criteria used by SPIP loops.
You can start by reading The syntax of SPIP's loops - SPIP on the loops
and browse Manuel de référence des boucles et balises - SPIP (unfortunately still in French) for each type of loop with its criteria.
But in a nutshell, if you want your articles sorted by title you just use {par titre}, if you want them all you use {tout} if you want to sort articles by keywords you use {id_mot} or by author you use {id_auteur} and so on.

George

Mattias Nyrell wrote:

ok, I have read that, but it's not that I wan't to apply a filter to the things I get from the DB, rather I wan't to tell spip what to get from the DB in the first place.

My site will have many articles on different subjects, and my idea is to allow the visitor to to do things like show all articles, show all authors and their articles, show all articles with a certain keyword, sort by title, sort by authorname, sort by date etc etc.

I can't use a different HTML/SPIP template for each of these variants. It wouldn't be very manageable...

Any ideas on how I could design a SPIP site with these features?

/Mattias

On Monday 29 September 2003 14.35, Simon Schneebeli wrote:

Try SPIP's tags: the syntax - SPIP

Simon

Mattias Nyrell wrote:
   

I couldnt access that page, it asks for a login...

/Mattias

On Monday 29 September 2003 11.45, George Kandalaft wrote:
     

Spip doesn't recognise filters this way. you have to define them in the
mes_fonctions.php3 file before you can use them in your boucles.
See the article at:
http://www.spip.net/ecrire/articles.php3?id_article=2055 on the subject.

George

Mattias Nyrell wrote:
       

Hi!

Is it possible to pass a variable to the loop? I want to do something
like this:

<?php
$sortBy = titre;
?>

<BOUCLE_articles(ARTICLES) {par $sortBy}>
       #TITRE<br>
</BOUCLE_articles>

The problem is that I can't create the boucle in PHP (spip complains
about wrong boucle syntax).

So... I have the information in a variable. Is it possible to pass it to
the spip loop somehow?

/Mattias

_______________________________________________
spip-en@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-en
         

_______________________________________________
spip-en@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-en
       

_______________________________________________
spip-en@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-en
     

_______________________________________________
spip-en@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-en
   
_______________________________________________
spip-en@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-en

ok. Thanks for your help.

Hmm... I got an idea...
In article_dist.html we have the following loop:

<BOUCLE_article_principal(ARTICLES) {id_article}>

Somehow this loop gets the value of $id_article. Are there anymore special
cases like this? Maybe I could use this somehow...

/Mattias

On Monday 29 September 2003 15.32, Antoine wrote:

Le lun 29/09/2003 à 15:02, Mattias Nyrell a écrit :
> ok, I have read that, but it's not that I wan't to apply a filter to the
> things I get from the DB, rather I wan't to tell spip what to get from
> the DB in the first place.
>
> My site will have many articles on different subjects, and my idea is to
> allow the visitor to to do things like show all articles, show all
> authors and their articles, show all articles with a certain keyword,
> sort by title, sort by authorname, sort by date etc etc.
>
> I can't use a different HTML/SPIP template for each of these variants. It
> wouldn't be very manageable...

But it's the only solution (except writing your own PHP/MySQL code, but
I guess you don't really want that). SPIP's loops are interpreted before
any PHP code, and there is no workaround I know of.

If you choose to write different templates for the different variants,
you can still <INCLUDE> some common parts so that the task is a little
easier for you. You can also do some clever loop nesting with
conditional codes (<//B_boucle>) so as to trigger different loops
depending on the URL parameters.

Hope that helps.

Antoine.

_______________________________________________
spip-en@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-en

Hello Mattias,
I come back to your first post :

So... I have the information in a variable. Is it possible to pass it to the
spip loop somehow?

No, you can't: it's a little bit as the problem of the chicken and the egg.

the reason is that SPIP is interpreted first, and then the result stored in the cache.
(see : http://www.spip.net/en_article2068.html) The SPIP loops are interpreted and ot genereates php pages with no more SPIP code. And the php code is recalculated each time you call the page, but no longer the SPIP code and the consequent calls to the MySQL database.
So, what about if your php variable has different values at each execution? In other words, the cache systems makes no sense to consider interpreting SPIP after php.

It's a bit sad the first time you here that, but on another hand, the cache system is one of SPIP strengths.

There are indeed some variables that you can handle within SPIP, like id_article , as you say. but these are few and specific (the id_ 's and see variables debut_ Les critères communs à toutes les boucles - SPIP)

You should consider re-thinking what you want to do, and there should be a proper SPIP-oriented way to do it.
Particularly, do not hesitate to use rubrique=NN.html skeletons. It may seem a "dirty" way for programers, but it's a good way in SPIP. To merge common parts of skeletons (menus, headers, bars, etc) use the <INCLURE(...)> command.

regards,

daniel

there is an article on spip, php and javascript, but in french:
http://www.uzine.net/spip_contrib/article.php3?id_article=50

---
Daniel Viñar Ulriksen
dani@easynet.fr

Thanks. I will try to do things the SPIP way... :slight_smile:

Particularly, do not hesitate to use rubrique=NN.html skeletons.

Could you explain that a bit more?

Why is it that SPIP is able to interpret the id_ variables? Is it because they
are sent in the URL? (.../spip/article.php3?id_article=6)

/Mattias

On Tuesday 30 September 2003 00.46, Daniel Viñar wrote:

Hello Mattias,

I come back to your first post :
> So... I have the information in a variable. Is it possible to pass it
> to the
> spip loop somehow?

No, you can't: it's a little bit as the problem of the chicken and the
egg.

the reason is that SPIP is interpreted first, and then the result
stored in the cache.
(see : http://www.spip.net/en_article2068.html) The SPIP loops are
interpreted and ot genereates php pages with no more SPIP code. And the
php code is recalculated each time you call the page, but no longer the
SPIP code and the consequent calls to the MySQL database.
So, what about if your php variable has different values at each
execution? In other words, the cache systems makes no sense to
consider interpreting SPIP after php.

It's a bit sad the first time you here that, but on another hand, the
cache system is one of SPIP strengths.

There are indeed some variables that you can handle within SPIP, like
id_article , as you say. but these are few and specific (the id_ 's and
  see variables debut_ Les critères communs à toutes les boucles - SPIP)

You should consider re-thinking what you want to do, and there should
be a proper SPIP-oriented way to do it.
Particularly, do not hesitate to use rubrique=NN.html skeletons. It
may seem a "dirty" way for programers, but it's a good way in SPIP. To
merge common parts of skeletons (menus, headers, bars, etc) use the
<INCLURE(...)> command.

regards,

daniel

there is an article on spip, php and javascript, but in french:
http://www.uzine.net/spip_contrib/article.php3?id_article=50

---
Daniel Viñar Ulriksen
dani@easynet.fr

Particularly, do not hesitate to use rubrique=NN.html skeletons.

Could you explain that a bit more?

the skeleton rubrique=5.html is used for section 5,
the skeleton rubrique-7.html is used for section 7 and all its subsections.

the skeleton article=3.html applies to article number 3
article-5.html for articles in section 5

Why is it that SPIP is able to interpret the id_ variables? Is it because they
are sent in the URL? (.../spip/article.php3?id_article=6)

because it is designed to.
but it has a very specific behaviour: it is used to extract such an article from the database.
the main interpretation is that different files are cached for each value of id_article.
It won't be the case for another php variable

At least it's what I understand...
Antoine, am I telling silly things?

daniel
---
Daniel Viñar Ulriksen
dani@easynet.fr