We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11975
    • 2,542 Posts
    Salut,

    c’est normal que ton procédé ne fonctionne pas.
    Lorsque tu ddes l’affichage de la valeur de ta TV depuis le doc css avec [*maTV*], modx cherche la valeur correspondante pour le document courant c’est a dire ta feuille de style et non le doc "html".
    Tu peux t’en sortir avec getField qui fonctionne également avec les TVs.

    :-)

    EDIT: en y réfléchissant, il va falloir ruser un peu pour passer l’id du doc courant à ton css.
    Tu devrais pouvoir t’en sortit en ajoutant à la suite du chemin [~[idDocCSS]~]?docid=[*id*] et modifie en consequence le snippet getField
    pour si $docid = (isset($_GET[’docid’])) ? $_GET[’docid’] : (isset($docid)) ? $docid : $modx->documentIdentifier;


      Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
      • 28173
      • 409 Posts
      Je viens d’essayer ton idée heliotrope.
      Le principe est intéressant mais j’ai un petit soucis.

      Voici ce que j’ai dans ma feuille de style :
       background-image: url({{imagebas}});


      Voici mon chunk {{imagebas}} :
      [[GetField?field=`imagebas`]]


      J’ai bien sûr modifié le snippet GetField comme tu l’as suggéré et modifié l’appel de la feuille de style dans le modèle comme suit :
      @import url('/css/styles.css?docid=[*id*]');


      Si je tente d’afficher ma feuille de style générée, j’ai cette erreur :
      Fatal error: Call to undefined function: gettv() in /var/www/virtual/mydomain.com/htdocs/manager/includes/document.parser.class.inc.php(748) : eval()’d code on line 211
      Si par contre dans mon chunk je remplace `imagebas` par `pagetitle` par exemple, la feuille de styles s’affiche correctement, avec de surcroît le nom de la page au bon endroit wink
        • 11975
        • 2,542 Posts
        re,

        essaie avec cette ligne:

        $id = (isset($_GET[’docid’])) ? $_GET[’docid’] : (isset($docid)) ? $docid : $modx->documentIdentifier;

        :-)
          Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
          • 28173
          • 409 Posts
          On est d’accord sur le fait qu’en mettant cette ligne dans le snippet, j’ai commenté la ligne existante qui est :
          $id = (isset($docid)) ? $docid : $modx->documentIdentifier;


          Car ça donne exactement la même erreur...
            • 11975
            • 2,542 Posts
            Salut,

            j’ai déjà eu cette erreur avec ce snippet.

            Quelle version de php utilises tu ?
            La solution la plus simple est de déplacer le code de la fonction getTV() en début du code du snippet.(avant qu’elle en soit appelée dans le snippet.

            :-)
              Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
              • 11975
              • 2,542 Posts
              Comme ça par exemple:

              /*
              
              ==================================================
              
              	GetField
              
              ==================================================
              
              
              
              Gets a field or template variable for current or
              
              specified document or its parent up to specified
              
              number of levels until ultimate parent is reached.
              
              
              
              Author: Grzegorz Adamiak [grad]
              
              Version: 1.2.2 @2006-10-25 08:54:45
              
              License: LGPL
              
              MODx: 0.9.2.1
              
              
              
              Uses idea of getDoc by Mark with modification from
              
              luke.stokes
              
              
              
              History:
              
              # 1.2.2
              
              - a quick fix to "Cannot redeclare function"
              
              # 1.2.1
              
              - reworked fetching of template variable (again ;)
              
                to enable output of widget
              
              # 1.2
              
              - reworked fetching of template variable value to
              
                get INHERITED value
              
              - removed defaulting to 'pagetitle' when $field
              
                not found; this is due to fact that tv can have
              
                empty value
              
              # 1.1.1
              
              - fixed small bug with $parentLevel and $topid
              
                check; now should work as expected
              
              # 1.1
              
              - reworked fetching of template variable value,
              
                now it gets computed value instead of nominal;
              
                however, still not the inherited value
              
              - changed license to LGPL
              
              # 1.0
              
              - first public release
              
              --------------------------------------------------
              
              */
              
              
              
              /* Parameters
              
              ----------------------------------------------- */
              # functions
              
              # ---------------------------------------------
              
              
              
              # gets (inherited) value of template variable
              
              if (!function_exists(getTV))
              
              {
              
              	function getTV($modx,$docid,$doctv)
              
              	{
              
              	/* apparently in 0.9.2.1 the getTemplateVarOutput function doesn't work as expected and doesn't return INHERITED value; this is probably to be fixed for next release; see http://modxcms.com/bugs/task/464
              
              		$output = $modx->getTemplateVarOutput($tv,$docid);
              
              		return $output[$tv];
              
              	*/
              
              		
              
              		while ($pid = $modx->getDocument($docid,'parent'))
              
              		{
              
              			$tv = $modx->getTemplateVar($doctv,'*',$docid);
              
              			if (($tv['value'] && substr($tv['value'],0,8) != '@INHERIT') or !$tv['value']) // tv default value is overriden (including empty)
              
              			{
              
              				//$output = $tv['value'];
              
              				$output = $modx->getTemplateVarOutput($doctv,$docid);
              
              				$output = $output[$doctv];
              
              				break;
              
              			}
              
              			else // there is no parent with default value overriden 
              
              			{
              
              				$output = trim(substr($tv['value'],8));
              
              			}
              
              			$docid = $pid['parent']; // move up one document in document tree
              
              		} // end while
              
              		
              
              		return $output;
              
              	}
              
              }
              
              
              # $docid [ int ]
              
              # Document for which to get a field.
              
              # Default: current document
              
              
               $id = (isset($_GET['docid'])) ? $_GET['docid'] : (isset($docid)) ? $docid : $modx->documentIdentifier;
              
              
              
              # $field [ string ]
              
              # Field to get for the document:
              
              # - any of the document object fields
              
              #   (http://modxcms.com/the-document-object.html)
              
              # - template variable assigned to the document
              
              # Default: 'pagetitle'
              
              
              
              $field = (isset($field)) ? trim($field) : 'pagetitle';
              
              
              
              # $parent [ 0 | 1 ]
              
              # $parent = 1 - returns the field for the parent
              
              # of the document.
              
              # Default: 0
              
              
              
              $parent = (isset($parent)) ? $parent : 0;
              
              
              
              # $parentLevel [ int ]
              
              # How high in the document tree to search for the
              
              # parent of the document?
              
              # - $parentLevel = 0 - returns the ultimate parent
              
              #   (right under site root)
              
              # - $parentLevel = 1 - returns the direct parent
              
              # Default: 0
              
              
              
              $parentLevel = (isset($parentLevel) && is_int((int) $parentLevel)) ? $parentLevel : 0;
              
              
              
              # $topid [ int ]
              
              # Id of the topmost document in the document tree
              
              # under which to search for a parent.
              
              # Default: 0
              
              
              
              $topid = (isset($topid) && is_int((int) $topid)) ? $topid : 0;
              
              
              
              /* End parameters
              
              ----------------------------------------------- */
              
              
              
              # search for parent document id
              
              # ---------------------------------------------
              
              if ($parent)
              
              {
              
              	# build an array of document's ancestors
              
              	$arrDocParents[] = $id; // add current document on first place
              
              
              
              	# get all parents back to root of document tree
              
              	while (($pid = $modx->getDocument($id,'parent')) && ($pid['parent'] != 0))
              
              	{
              
              		$id = $pid['parent']; // move up one document in document tree
              
              		$arrDocParents[] = $id; // add parent to array of document's ancestors
              
              	} // end while
              
              	$countParents = count($arrDocParents);
              
              
              
              	# determine the parent id
              
              	switch ($topid)
              
              	{
              
              		case 0: // not set or set to root of document tree
              
              
              
              			($parentLevel && ($parentLevel < $countParents)) ?
              
              				($docid = $arrDocParents[$parentLevel]) : // find parent in specified levels up
              
              				($docid = $arrDocParents[$countParents - 1]);
              
              
              
              			break;
              
              
              
              		default: // set to any other document
              
              
              
              			$key = array_search($topid, $arrDocParents); // find the index of parent
              
              			switch ($key)
              
              			{
              
              				case 0: // not an ancestor or the document itself
              
              
              
              					$docid = 0;
              
              					break;
              
              
              
              				default: // parent is above the document in document tree
              
              
              
              					($parentLevel && ($parentLevel < $key)) ?
              
              						($docid = $arrDocParents[$parentLevel]) : // find parent in specified levels up
              
              						($docid = $arrDocParents[$key - 1]);
              
              			} // end switch
              
              	} // end switch
              
              } // end if
              
              else
              
              {
              
              	$docid = $id;
              
              } // end else
              
              
              
              # get field or template variable for document
              
              # ---------------------------------------------
              
              // check for document field
              
              $docFields = $modx->getDocument($docid);
              
              $output = $docFields[$field];
              
              
              
              // check for template variable
              
              if (!$output)
              
              {
              
              	$output = getTV($modx,$docid,$field);
              
              }
              
              
              
              return $output;
              
              
              
              
              
              
              
                Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
                • 28173
                • 409 Posts
                Effectivement il y a du mieux smiley
                Mais la TV ne semble pas arriver convenablement dans la feuille de style.
                En effet, si je choppe grâce à une extension Firefox spécifique les caractéristiques de mon DIV devant recevoir l’image de fond propre à la page, il me sort que la propriété background-image est "styles.css?docid=4" au lieu d’être le chemin de l’image.

                Pourtant si je place l’appel de GetField dans une page comme ça : [[GetField?field=`imagebas`]], j’obtiens bien le bon chemin de l’image...
                  • 28173
                  • 409 Posts
                  Finalement j’ai choisi la simplicité pour le moment en ajoutant une balise <style> dans mon modèle. Cette balise contient ma TV qui va bien pour changer un élément en fonction de la page où l’on se trouve.

                  En attendant je réitère mes félicitations pour ce tutoriel smiley
                    • 21101
                    • 169 Posts
                    je sais pas, j’avais essayé aussi mais ça ne marchait pas... j’utilise [(site_url)], par contre je le fais dans mes pages quand je fais appel a une image wink
                      Play no games
                      • 11975
                      • 2,542 Posts
                      Hello,

                      en fait l’appel d’un TV depuis un document sans template assignée (c’est le cas d’un doc avec type="text/css") ne peut pas fonctionner en raison de la requête sql de la fonction getTemplateVars qui est invoque dans getTemplateVarOutput
                      (pour le detail document.parser.inc.php)
                      Il faudrait écrire sa propre fonction pour que ça marche

                      :-)
                        Made with MODx : [url=http://www.copadel.com]copadel, fruits et l