I use pyrocms to develop a site. I need to use stream for a view. I would like only the entries corresponding to the current user to be displayed. I use the following query (user_id is name of the field on my database)
{{ streams:cycle stream="{{ stream }}" where="`user_id`='{{user:id}}'" order_by="nom" sort="asc"}}
Pyrocms works like if my request stop before the where clause. and it show me this on the page :
1 '" order_by="nom" sort="asc"}}
and I view all results on the page (all entries for all users).
If I'm using this request it works :
{{ streams:cycle stream="{{ stream }}" where="`user_id`=1" order_by="nom" sort="asc"}}
What do I do wrong? Can I use variable on the where clause ?
Thanks Matthieu
To start, try {{ streams:cycle stream="
stream_name
".... without the curly braces and the stream name is enclosed in back-ticks, second, is the user_id a field in the stream you are accessing? The following is an extract from the Streams Plug In documentation:Note: The where clause is directly mapped to the where clause in MySQL, so you are limited in the values that you can restrict by. For instance, if you have a Choice dropdown field with a key and value, the key is stored in the database. So, if you want to restrict by that field, you need to restrict by the choice key and not the value.
You may need to have a stream for the users and use the Relationship field type. For example:
{{ streams:users where="
active
='1'"... }}{{ /streams:users }}
note that {{ id }} is the id of the entry in the users stream. Note again the requirement for back ticks - but it looks like you have that under control based on your code samples
Hope this helps.