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

    How can I apply a function to the content of a page?

    I have to make a website in esperanto and in some cases, some characters are not displayed correctly, for example ŭ. In these cases I have to give the possibility to replace this character by ux or u’ or ... (the user decides). There an example here (the orange box) : http://www.esperantio.net
    I want to pass the content in a function which look like :

    function convert($content, $modifType) {
        if($modifType = "'") {
            str_replace("& #365;", "u'", $content);
        } elseif($modifType "x") {
            str_replace("& #365;", "ux'", $content);
        }
    
        // ...
        return $content
    }
    


    $modifType is send by a form ($_POST or $_GET).


    But I don’t know how I can do that.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Sounds like you need a plugin, something like this one:

      http://modxcms.com/forums/index.php/topic,3832.msg27697.html#msg27697
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 25663 MODX Staff
        • 12,272 Posts
        Or you could create a TV that uses the @EVAL binding on the content as it’s default content and place the TV in the template instead of the content. Changes up the searching a bit, but would work.
          Ryan Thrash, MODX Co-Founder
          Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
          • 15114
          • 102 Posts
          Quote from: rthrash at May 04, 2006, 11:27 AM

          Or you could create a TV that uses the @EVAL binding on the content as it’s default content and place the TV in the template instead of the content. Changes up the searching a bit, but would work.

          With something like :

          @EVAL
          $myContentVar = $modx->documentObject['content'];
          // what I want to modify in my content
          return $myContentVar
          


          and in my template y replace [*#content*] by [*myContentVar*]


          Is it right ?


          In [*#content*], what does mean the # ?
            • 10487 MODX Staff
            • 1,535 Posts
            Hi JuTs, the hash means that it will be directly editable using the QuickEdit plugin. (i.e. you’d get a ’Edit myContentVar’ button when logged in the front end)
              Garry Nutting
              Senior Developer
              MODX, LLC

              Email: [email protected]
              Twitter: @garryn
              Web: modx.com
              • 15114
              • 102 Posts
              I managed to modify the content but I have some problems with the cache.
              The visitor chooses the type of display with a form and the content is modified by the TV. But if the page is in the cache, the content is not modified.

              My TV :
              @EVAL
              $myContentVar = $modx->documentObject['content'];
              
              if(isset($_POST['disp_type']))
              {
              	$_SESSION['disp_type'] = $_POST['disp_type'];
              	setcookie('disp_type', $_POST['disp_type'], time()+365*24*60*60, "/");
              }
              elseif(isset($_COOKIE['disp_type']))
              {
              	$_SESSION['disp_type'] = $_COOKIE['disp_type'];
              }
              else
              {
              	$_SESSION['disp_type'] = '';
              }
              
              switch($_SESSION['disp_type'])
              {
              	case 'x' :
              	$char_disp = array('cx', 'cx', 'Cx', 'Cx}',
              			'gx', 'gx', 'Gx', 'Gx',
              			'hx', 'hx', 'Hx', 'Hx',
              			'jx', 'jx', 'Jx', 'Jx',
              			'sx', 'sx', 'Sx', 'Sx',
              			'ux', 'ux', 'Ux', 'Ux');
              	break;
              
              	case 'h' :
              	$char_disp = array('ch', 'ch', 'Ch', 'Ch}',
              			'gh', 'gh', 'Gh', 'Gh',
              			'hh', 'hh', 'Hh', 'Hh',
              			'jh', 'jh', 'Jh', 'Jh',
              			'sh', 'sh', 'Sh', 'Sh',
              			'uh', 'uh', 'Uh', 'Uh');
              	break;
              
              	case 'a' :
              	$char_disp = array("c'", "c'", "C'", "C'}",
              			"g'", "g'", "G'", "G'",
              			"h'", "h'", "H'", "H'",
              			"j'", "j'", "J'", "J'",
              			"s'", "s'", "S'", "S'",
              			"u'", "u'", "U'", "U'");
              	break;
              
              	case 'c' :
              	$char_disp = array('c^', 'c^', 'C^', 'C^}',
              			'g^', 'g^', 'G^', 'G^',
              			'h^', 'h^', 'H^', 'H^',
              			'j^', 'j^', 'J^', 'J^',
              			's^', 's^', 'S^', 'S^',
              			'u^', 'u^', 'U^', 'U^');
              	break;
              
              	default:
              	$char_disp = array('ĉ', 'ĉ', 'Ĉ', 'Ĉ}',
              				'ĝ', 'ĝ', 'Ĝ', 'Ĝ',
              				'ĥ', 'ĥ', 'Ĥ', 'Ĥ',
              				'ĵ', 'ĵ', 'Ĵ', 'Ĵ',
              				'ŝ', 'ŝ', 'Ŝ', 'Ŝ',
              				'ŭ', 'ŭ', 'Ŭ', 'Ŭ');
              }
              
              $char_src = array('cx', '{cx}', 'Cx', '{Cx}',
              		'gx', '{gx}', 'Gx', '{Gx}',
              		'hx', '{hx}', 'Hx', '{Hx}',
              		'jx', '{jx}', 'Jx', '{Jx}',
              		'sx', '{sx}', 'Sx', '{Sx}',
              		'ux', '{ux}', 'Ux', '{Ux}');
              
              $myContentVar = str_replace($char_src, $char_disp, $myContentVar);
              
              return $myContentVar;
              
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                If an entire document’s content is to be dynamic, then it seems the logical thing that that docuement should not be cached at all.
                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                  • 15114
                  • 102 Posts
                  Yes, but is it possible to indicate to MODx if it have to put the in the cache ?

                  In my case the majority of the visitors will use the default option.
                  I would like to do something like :

                  if($_SESSION[’disp_type’] == "")
                  take the page from the cache if exists and put the page in the cache if not
                  else
                  don’t put the page in the cache


                  If it’s not possible I disable the cache
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    You could make a plugin that would delete the cached document before the parser goes to look for it. You would also have to set the documentObject[’cacheable’] to 0 so it won’t cache this version. Possible, but I would not recommend it.

                    Simply not caching that one page is not going to cause a big problem and would be a lot easier, not to mention that messing around with the caching functioning is asking for odd things to happen.
                      Studying MODX in the desert - http://sottwell.com
                      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                      Join the Slack Community - http://modx.org