We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36870
    • 13 Posts
    Im going by the code snippet below from http://rtfm.modx.com/display/revolution20/PHP+Coding+in+MODx+Revolution,+Pt.+I

    // getting a resource (i.e. a page) that is published, with a alias of 'test'
    $document = $modx->getObject('modResource',array(
    'published' => 1,
    'alias' => 'test',
    ));

    I'm creating a store and now I just need to access my resources so I can do things like,
    1) access an array of children (products)
    2) create a search form to search all product descriptions for keywords typed in the search

    maybe i'm misunderstanding what 'alias' is but im trying to access a single wig resource with

    // getting a resource (i.e. a page) that is published, with a alias of 'test'
    $document = $modx->getObject('modResource',array(
    'published' => 1,
    'alias' => 'synthetic-wig-1',
    ));

    synthetic-wig-1 being the url alias of the resource

    anyways when I add that line of code to a php snippet that displays products it breaks the page and gives me a

    HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request

    Please, any assistance would be greatly appreciated. I'm fairly new to web world and especially complex php sites with a CMS. the site is http://thehaircorporation.com/

    EDIT: I just realized my version when look in my manager info is MODx version 1.0.5
    is this version Evolution or Revolution? Am I on an old version?

    Thank you,
    William
    [ed. note: whaus77 last edited this post 12 years, 3 months ago.]
      • 31946
      • 116 Posts
      MODx 1.0.5 is Evolution, the code you tried only works with MODx Revolution.
        • 4041
        • 788 Posts
        Evolution is the older version but is still quite viable. The best info at the moment regarding evo is here:
        http://wiki.modxcms.com/index.php/Main_Page

        And here is some sample snippet code which might help:
        <?php
        /*
           * create a new snippet named "ItemLister" (without the quotes) and use this code as the snippet content.
           * on the page where you want the list to appear, add this call
             to the page content:
             
             [!ItemLister!]
             
             or
             
             [!ItemLister? &tpl=`YourChunkName` &parent=`10`!]
           
        */
        
        $output ='';
        
        $default_tpl ='
        <table width="200" style="float: left; margin-bottom: 10px; margin-right: 5px; margin-left: 5px; border-style: dotted; border-color: #e92e85; border-width:1px; padding-left: 44px; padding-right: 44px; padding-top: 15px; padding-bottom: 15px;">
            <tr>
                <td><center>
                    <div class="TitleStyle2">[+pagetitle+]</div>  </center>
                </td>
            </tr>
            <tr>
                <td><center>
                    <a href="[~[+id+]~]"><img style="border:2px solid #000000" src="images/[+image+].jpg" alt="[+description+]" width="152" height="210" /></a>
                    </center>
                </td>
            </tr>
            <tr>
                <td><center>
                    <a href="[~[+id+]~]"><img style="border:0px" src="images/item-details-button.jpg" oncontextmenu="return false;" alt="" width="130" height="30" /></a>
                </center></td>
            </tr>
        </table>
        ';
        
        
        $parent = isset($parent) ? $parent : $modx->documentObject['id'];
        $tpl = isset($tpl) && $modx->getChunk($tpl) !='' ? $modx->getChunk($tpl) : $default_tpl;
        
        $select ='*';
        $where  ='parent="'.$parent.'" AND published="1"';
        $sort   ='menuindex ASC';
        $limit  ='';
        
        $found = $modx->db->makeArray($modx->db->select($select,$modx->getFullTableName('site_content'), $where, $sort, $limit));
        if(!$found) return $output;
        
        $fcount = count($found);
        for($x=0; $x<$fcount; $x++) {
        
            $fimage = explode('-',$found[$x]['alias']);
            $found_image = $fimage[0] .'-'.$fimage[1].'-small-'.$fimage[2];
            
            $f_array = array(
                '[+id+]'           => $found[$x]['id'],
                '[+image+]'        => $found_image,
                '[+description+]'  => $found[$x]['description'],
                '[+pagetitle+]'    => $found[$x]['pagetitle'],
                '[+longtitle+]'    => $found[$x]['longtitle'],
                '[+introtext+]'    => $found[$x]['introtext']
                //'[+content+]'      => $found[$x]['content']
            );
            $output .=str_replace(array_keys($f_array), array_values($f_array), $tpl);
        
        }
        
        return $output;
        
        [ed. note: breezer last edited this post 12 years, 3 months ago.]
          xforum
          http://frsbuilders.net (under construction) forum for evolution
          • 36870
          • 13 Posts
          First of all thank you so much for responding so quickly and the Evolution wiki reference

          Ok I'm a little over my head here, this is my first time working with a advanced php snippet. First real CMS website. im coming from c++ game dev. world

          what is that code snippet doing exactly, im a little lost.. =(

          I'm going to start small, I have a parent resource for example "synthetic-wigs" with children of
          "synthetic-wig-1"
          "synthetic-wig-2"
          "synthetic-wig-3"
          "synthetic-wig-4"

          right now I just want my parent resource "synthetic-wigs" to contain a snippet that loops threw all the children gathering the "title" and "image name".

          Then displaying the title and images just like it is now like http://www.thehaircorporation.com/synthetic-wigs.html with the wig selection but I'm doing it static "very ghetto and not efficient" and I want it to be dynamic so when I add a product its automatically displayed in my parents list instead of manually adding the product title and image name AND url name to "synthetic-wigs" resource...

          Hope I explained that right, and sorry for being an idiot...

          Thanks again!

          [ed. note: whaus77 last edited this post 12 years, 3 months ago.]
            • 4041
            • 788 Posts
            I amended the code in my previous post so copy that code and see the comments at the top to create the snippet.

            What the snippet does:
            1. checks to see if you are calling a custom chunk tpl in the snippet call (if not, it uses the $default_tpl)
            2. checks to see if you have set a parent in the snippet call (defaults to current document)
            3. looks for any published children and creates an array of the $found items
            4. parses each item found and adds to the $output
            5. returns the $output, which prints the items smiley
              xforum
              http://frsbuilders.net (under construction) forum for evolution
              • 36870
              • 13 Posts
              wow your amazing... I totally understand whats going now but still got some issues... so I have a page http://thehaircorporation.com/search-results

              I also added a duplicate wig as a child to this page. I then added the [!ItemLister!] snippet to the content section of "search-results" but i thought snippets used the double [[ ? I dunno I used both syntax but neither showed my child wig I added.

              Its just ignoring the snippet call, not displaying any of the code, honestly I dont understand the [+pagetitle+] and [~[+id+]~] . am I suppose to use [*pagetitle*] for evolution?

              Do I need to modify your code your gave me at all? maybe just some revolution/evolution syntax issue.

              Again... thanks so much Breezer, your freakin amazing help. not sure what the prob is now tho.

              EDIT: im just trying the default snippet call so search-results is the parent and im using the default chunk. thanks sooooooooooo much for the help. I was clueless before.

              [ed. note: whaus77 last edited this post 12 years, 3 months ago.]
                • 4041
                • 788 Posts
                Sorry I had not tested the code before I posted and found a couple spelling mismatches (single quotes need to be changed to double quotes). I had to change two lines in the code above:

                line 26 changed:
                style='border:2px solid #000000'
                to this:
                style="border:2px solid #000000"

                and line 32 changed:
                style='border:0px'
                to this:
                style="border:0px"

                See if that helps.
                  xforum
                  http://frsbuilders.net (under construction) forum for evolution
                  • 36870
                  • 13 Posts
                  holy crap, I dont know how to thank you enough Breezer. You've been a HUUUUUUUUUUUUUUUUUUGE help. ill be smooth sailing now!

                  thank you thank you thank you!!!!
                    • 4041
                    • 788 Posts
                    To explain further, the snippet was made to be called on your items list page. Then when you edit the child documents the following fields are used:
                    1. the link alt text comes from the document description.
                    2. the image name is created from the document alias, with the "small" added
                    3. the item title is the document pagetitle
                    4. the link to the document is created using the document id

                    You might have to add your container wrapper around the snippet if necessary, I don't know how you have your template set up.

                    Your welcome smiley
                      xforum
                      http://frsbuilders.net (under construction) forum for evolution