We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • Menno Pietersen Reply #1, 11 years ago
    So I am working on a new version of my Flexibility template.
    I want to use mycomponent this time (great Extra Bob!) to test an package it.

    I have this for the chunks and template part now, it is working except for the content of the template and chunk files...
    My goal is to use static files in my template everywhere.

    'elements' => array(
            'chunks' => array(
                'flex-4-header' => array(
                    'category' => 'flex-4',
                    'description' => 'Header of the flexibility4 template',
                    'static' => true,
                    'filename' => 'flex-4-header',
                ),
                'flex-4-footer' => array(
                    'category' => 'flex-4',
                    'description' => 'Footer of the flexibility4 template',
                    'static' => true,
                    'filename' => 'flex-4-footer',
                ),
            ),
            'templates' => array(
                'Homepage template' => array(
                    'category' => 'flex-4',
                    'description' => 'Homepage template of Flexibility 4',
                    'static' => true,
                    'filename' => 'flex-4-homepage',
                ),
            ),
        ),
    


    The content of both chunks becomes:
    <p>Chunk content goes here</p>

    And the content of the template files becomes:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>[[++site_name]] - [[*pagetitle]]</title>
    <base href="[[++site_url]]"/>
    </head>
    <body>
    [[*content]]
    </body>
    </html>

    Somehow the build script seems to override the content of my files!

    Anybody know why and how I change this?


    ----BONUS QUESTION-----

    If I end up not using static files how do I get the right content in the chunk? (probably related)
      MODX Ambassador (NL) | Responsive web design specialist, developer & speaker
      DESIGNfromWITHIN, MPThemes and Any Screen Size
      Follow me on Twitter | Read my blog | My code on GitHub
      • 3749
      • 24,544 Posts
      Sorry Menno, the Forum didn't show me this as an unread post for some reason.

      I tend not to use static elements, so there may be some quirks there (and I recently made some changes to how static elements are handled).

      I need to know more about the exact steps you followed to get to that point.

      What I would try in that situation is to run Bootstrap with no files present -- that will create the files (with the content you show). Then (after making sure the object types are in the 'process' list), I'd copy the real files over the existing ones and run Import Objects, then Export Objects.


      After that, the build should work correctly. Let me know if it doesn't.





        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
      • Menno Pietersen Reply #3, 11 years ago
        Thanks so much Bob,


        Still some issues,
        Bootstrapping create the normal files, if I change the new files they still get the wrong content.

        I the 'old' package I used a "Transport.chunks.php" file to link the content to my chunks like this:

        $chunks[3]= $modx->newObject('modChunk');
        $chunks[3]->fromArray(array(
            'id' => 3,
            'name' => 'page_gallery',
            'description' => 'Gallery chunk',
            'snippet' => file_get_contents($sources['data'].'/chunks/page_gallery.tpl'),
            'properties' => '',
        ),'',true,true);


        How is this done in MyComponent? Can I stull use a transport.chunks.php file in it?

        I have thought about it do not really need static elements but do need to have the MyComponent package to get the content from the correct chunk from a file inside MyComponent.

        The steps I need, what I have now:


        1. MyComponent should create a header chunk called "flex-4-header" (this works file)
        2. MyComponent should the the content for "flex-4-header" from a html file placed in 'elements/chunks/flex-4-header.html' (this does not work, all elements get the 'deafult' content from the wrong file)

        'elements' => array(
                'chunks' => array(
                    'flex-4-header' => array(
                        'category' => 'flex-4',
                        'description' => 'Header of the flexibility4 template',
                        'static' => false,
                        'source' => 1,
                        'snippet' => file_get_contents('elements/chunks/flex-4-header.html'),
                    ),
                    'flex-4-footer' => array(
                        'category' => 'flex-4',
                        'description' => 'Footer of the flexibility4 template',
                        'static' => false,
                        'source' => 1,
                        'snippet' => file_get_contents('elements/chunks/flex-4-footer.html'),
                    ),
                ),
                'templates' => array(
                    'Homepage template' => array(
                        'category' => 'flex-4',
                        'description' => 'Homepage template of Flexibility 4',
                        'static' => false,
                        'source' => 1,
                        'snippet' => file_get_contents('elements/templates/index.html'),
                    ),
                ),
            ),


        Somehow all chunks created get the content from the file:
        core\components\mycomponent\elements\chunks\modchunk.tpl

        I can not see why this happens and where to change this. [ed. note: ThaClown last edited this post 11 years ago.]
          MODX Ambassador (NL) | Responsive web design specialist, developer & speaker
          DESIGNfromWITHIN, MPThemes and Any Screen Size
          Follow me on Twitter | Read my blog | My code on GitHub
        • Menno Pietersen Reply #4, 11 years ago
          Bob,

          I you will, I need more help.

          How can I have files in my package (css, js, html) and have the packege move them to: "media > assets > components > flexibility4"
            MODX Ambassador (NL) | Responsive web design specialist, developer & speaker
            DESIGNfromWITHIN, MPThemes and Any Screen Size
            Follow me on Twitter | Read my blog | My code on GitHub
            • 3749
            • 24,544 Posts
            It's possible that Export Objects is getting the old file content from the cache. You could try manually deleting everything in the core/cache/ directory before running Export Objects.

            More likely, though, is a problem with the file names and/or locations. See the section here on file names (under "Existing Project"): http://bobsguides.com/mycomponent-tutorial.html.

            I think your best bet is to specify the file names in the project config file like this:

            'chunks' => array(
                        'flex-4-header' => array(
                            'category' => 'flex-4',
                            'description' => 'Header of the flexibility4 template',
                            'static' => false,
                            'source' => 1,
                            // 'snippet' => file_get_contents('elements/chunks/flex-4-header.html'),
                            'filename' => 'flex-4-header.html', // this field is stripped out when the transport file is written
                             
                        ),
            ),


            I think you might be able to leave them as static if you do that.


            There will be a transport.chunks.php file created automatically by Export Objects, but it will be in the _build/data/flex-4/ directory. You shouldn't have to modify it (and if you do, your changes will be overwritten when you run Export Objects.

            How can I have files in my package (css, js, html) and have the package move them to: "media > assets > components > flexibility4"

            Try changing this code in build.transport.php:

             if ($hasAssets && $i == 1) {
                    $helper->sendLog(MODX::LOG_LEVEL_INFO,
                        $modx->lexicon('mc_packaged_assets_files'));
                    $vehicle->resolve('file', array(
                                                   'source' => $sources['source_assets'],
                                                   'target' => "return MODX_ASSETS_PATH . 'components/';",
                                              ));
                }
            


            to something like this:

             if ($hasAssets && $i == 1) {
                    $helper->sendLog(MODX::LOG_LEVEL_INFO,
                        $modx->lexicon('mc_packaged_assets_files'));
                    $vehicle->resolve('file', array(
                                                   'source' => $sources['source_assets'],
                                                   'target' => "return MODX_BASE_PATH . 'media/assets/components/flexibility4/';",
                                              ));
                }
            


            Once the build.transport.php file exists, MyComponent won't ever modify it. This is the only change I'd recommend making to it, though.

              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
            • Menno Pietersen Reply #6, 11 years ago
              Thanks so much Bob!

              I was the cache... (note to self: always try to clear cache!)
                MODX Ambassador (NL) | Responsive web design specialist, developer & speaker
                DESIGNfromWITHIN, MPThemes and Any Screen Size
                Follow me on Twitter | Read my blog | My code on GitHub
              • Menno Pietersen Reply #7, 11 years ago
                Again the same problem. I tried to create a fresh setup tot start for real.

                Cleared cache, tried everything, the chunk and template still gets overwritten...
                Any more idea's? Could I give you acces to the MODX Cloud? Maybe you see the problem?

                My code:
                'elements' => array(
                
                        'chunks' => array(
                            'flex-4-header' => array(
                                'category' => 'flexibility4',
                                'description' => 'Header of the flexibility4 template',
                                'static' => false,
                                'source' => 1,
                                'filename' => 'flex-4-header.html',
                            ),
                            'flex-4-footer' => array(
                                'category' => 'flexibility4',
                                'description' => 'Footer of the flexibility4 template',
                                'static' => false,
                                'source' => 1,
                                'filename' => 'flex-4-footer.html',
                            ),
                        ),
                        'templates' => array(
                            'Homepage' => array(
                                'category' => 'flexibility4',
                                'description' => 'Template for a homepage',
                            ),
                        ),
                    ),



                Is there a other way to get content in the Chunks, TV's and Templates?
                  MODX Ambassador (NL) | Responsive web design specialist, developer & speaker
                  DESIGNfromWITHIN, MPThemes and Any Screen Size
                  Follow me on Twitter | Read my blog | My code on GitHub
                  • 3749
                  • 24,544 Posts
                  I tried everything and it seemed to work perfectly.

                  I wonder if you're using Import and Export backwards?


                  Whenever you modify files on the server, you should run Import Objects to update the object in MODX.

                  Whenever you modify objects in the Manager, you should run Export Objects to update the files.

                  I always clear the cache *after* running Import Objects and *before* running Export Objects. I'm not sure if that's necessary, but I do it anyway.
                    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