We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 45374
    • 18 Posts
    I'm just trying to get this set up to prove that I can do it.

    I have worked through the CMP tutorial.

    My index.php file looks like this:

    <?php
      $modx->lexicon->load('mycmp:default');
      return 'Hello from my CMP!';
    ?>
    


    This is my default.inc.php file in my /lexicon/en folder:

    <?php
      $_lang['mycmp'] = 'This is my CMP!';
      $_lang['mycmp.menu_desc'] = 'This is a description of my CMP!';
      $_lang['mycmp.message'] = 'A special message for you!';
      $_lang['mycmp.magic_word'] = 'xyzzy';
    ?>
    
    


    Everything shows up just fine inside MODx-- the first two strings from the english lexicon show up in the dropdown under components and when I click on it, the text "Hello from my CMP!" appears as expected.

    Everything works so far!

    In the content box for my home page I put this:

    Hello!
    
    [[%key? &topic=`magic_word` &namespace=`mycmp` &language=`en`]]
    
    ...


    When I hit "view", a new tab opens in my browser that says "Hello! key ..."

    This is not what I expected. I wanted to see "xyzzy" instead of "key".

    Similarly, when I change my index.php file to this:

    <?php
      $modx->getService('lexicon','modLexicon');
      $modx->lexicon->load('mycmp:default');
      $modx->lexicon->load('en:mycmp:magic_word');
      return $modx->lexicon('en:mycmp:magic_word');
      //return 'Hello from my CMP!';
    ?>
    


    The text that appears when I click on my component says "en:mycmp:magic_word".

    This also is not what I expected.

    I have tried several variations of these commands, but none of them work.

    What am I doing wrong?

    Update:

    [[%magic_word? &namespace=`mycmp` &topic=`default`]]

    This tag returns "magic_word". Not good!

    Same thing with this: [[%magic_word? &namespace=`mycmp` &topic=`default` &language=`en`]]

    Update 2:

    I have added this tag to my content:

    [[LoadLexicon? &topic=`mycmp`]]


    And added in this snipped:

    <?php
    $modx->getService('lexicon','modLexicon');
    $modx->lexicon->load($topic);
    return '';


    Still not there!

    Update 3:

    Tried this style for the snippet call:

    [
    [!LoadLexicon? &input=`mycmp`]]


    Not working, either. [ed. note: coderjeff last edited this post 12 years, 10 months ago.]
      • 3749
      • 24,544 Posts
      Try this with your original lexicon->load() call.

      [[%mycmp.magic_word? &topic=`magic_word` &namespace=`mycmp` &language=`en`]]


      The 'key' is literally what's in the quotes in $_lang[''] = in your .inc.php file.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 45374
        • 18 Posts
        Eh, I still couldn't get it to work.

        Thanks for the clarification, though.

        I will go home and cry some more now....
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          the "topic" is actually the name of the file. For example, looking at the lexicons for the Login snippet, you first have the namespace "login", then the language could be any one of the language directories in the login component's lexicon directory, and the topic would be the first part of one of the files in the specified language directory. For example, to use the register.inc.php file, the topic would be "register".
            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
            • 3749
            • 24,544 Posts
            Check the namespace for your CMP (or create one if you haven't) in System | Namespaces. The namespace's core path should be:

            {core_path)components/mycmp/


            And your lexicon file should be in

            core/components/mycmp/lexicon/en
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting