Personal tools
You are here: Support Documentation How-tos Random images
Document Actions

Random images


This How-to is intended for: Any audience.

Créer un portlet qui affiche des images aléatoires

===================

Création 'portlet' randomphoto

==============================

 

-ZMI>portal_skins>custom

-Add Page Template, ID portlet_randomphoto

-Editer 'portlet_randomphoto' remplacer l intégralité du code par par le '##SCRIPT_1 ou le ##SCRIPT_2

 

##SCRIPT_1

#########################CODE SANS LIEN PHOTO################################

 

<html><body>

<div metal:define-macro="portlet">

     <div  id="portlet_randomphoto"

             tal:define="presults python:context.portal_catalog(portal_type='Image',

                         path='/id_site/chemin_du_repertoir_img')"

             tal:condition="presults">

             <div>

 

               <span tal:define="pobj python:random.choice(presults).getObject()">

                     <img tal:replace="structure pobj/image" />

                     <span tal:content="string:${pobj/Description}">[displays description of image]</span>

               </span>

          </div>

     </div>

</div>

</body></html>

 

#########################/CODE SANS LIEN PHOTO################################

 

 

##SCRIPT_2

#########################CODE AVEC LIEN PHOTO################################

 

 <html xmlns:tal="http://xml.zope.org/namespaces/tal"

        xmlns:metal="http://xml.zope.org/namespaces/metal"

        i18n:domain="plone">

    <body>

 

      <div metal:define-macro="portlet">

        <div class="portlet" id="portlet_randomphoto"

             tal:define="presults python:container.portal_catalog(Type='Image',

                         review_state=['published','visible'],

                         path='/id_site/chemin_du_repertoir_img')"

             tal:condition="presults"

             tal:on-error="nothing" >

          <h5 i18n:translate="box_rndphoto">Photo</h5>

          <div class="portletBody" 

               tal:on-error="nothing">

            <tal:block

               tal:define="pobj

                           python:random.choice(presults).getObject()">

              <div class="portletContent odd" align="center">

 

                <a href=""

                   tal:attributes="href string:${pobj/absolute_url}/view">

                  <b tal:content=" string:${pobj/Title}" />

                  <br/>

                  <img

                     tal:attributes="src

                                     string:${pobj/absolute_url}/image_thumb"

                     alt="" />

                </a>

              </div>

            </tal:block>

          </div>

        </div>

      </div>

</body></html>

 

#########################/CODE AVEC LIEN PHOTO################################

 

- Modifier les variables dans la ligne 'path'

- Sauver

- Déclarer 'here/portlet_randomphoto/macros/portlet' dans les propriétés du dossier voulu (onglet 'Properties' | 'right_slots'ou 'left_slots')

- Tester

---> Il est également possible d'ajouter des styles css...

[pour connaitre 'id_site' aller dans ZMI> portal_catalog (par exemple)> onglet'catalog' regarder le ou les sous-répertoire(s), des fichiers indexés, avant la racine de votre site]

 


Powered by Plone CMS, the Open Source Content Management System