We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15987
    • 786 Posts
    I am working on setting up a new site and am getting an error with one of my template variables. Here is my problem:

    In my template I have [*SidebarContent*], this is used to show items on the right side of my page.
    I have created a folder named Sidebar Items and then have different documents under that (i.e. Searchbox, updated pages, etc).
    In my template variable [*SidebarContent*] I use the following @select to get my list of items:

    @SELECT pagetitle, concat("@document ",id) as selvalue from modx_site_content where parent=2


    I am also using a multi select list box, so a user could select multiple items for the sidebar.

    When I select one item from the list it works correctly, however when Iselect multiple items for the tv, I get the following error:

    MODx encountered the following error while attempting to parse the requested resource:
    « Execution of a query to the database failed - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '4) AND sc.published=1 AND sc.deleted=0 ) AND (sc.privateweb=0) LIMIT 1' at line 3 »
          SQL: SELECT DISTINCT sc.* FROM `dbname`.modx_site_content sc LEFT JOIN `dbname`.modx_document_groups dg on dg.document = sc.id WHERE (sc.id IN (3||@document 4) AND sc.published=1 AND sc.deleted=0 ) AND (sc.privateweb=0) LIMIT 1 


    I see that the error is probably due to me using the @document binding but am not sure how to fix it. If anyone can help with this I would appreciate it. Or if there is a better way to do this I would appreciate the input.

    Thanks in advance,

    Kyle
      • 32241
      • 1,495 Posts
      dunno for sure what you’re trying to accomplish, but here is another workaround that you can use.

      use textarea for the input field of your tv, to have a bigger editing field, and @EVAL binding. After that binding, you can insert whatever php code in it such as
      @EVAL
      $pagetitle = 'some_title';
      $rs = $modx->db->query("SELECT * FROM ".$modx->db->getTableName('site_content')." WHERE pagetitle = '$pagetitle'");
      $out = '';
      while($row = mysql_fetch_array($rs)) {
      $out .= $row['pagetitle'];
      }
      return $out;
      


      I haven’t tested the code, but it should work, but I thik it’s better if you check whether the db->getTableName is on our API or not. I might mistype the function name. Check newslisting snippet for better idea on how to use modx api. Just make sure that you need to return the output for tv to received it and output it to the screen when you call it.

      Sincerely.
        Wendy Novianto
        [font=Verdana]PT DJAMOER Technology Media
        [font=Verdana]Xituz Media
        • 15987
        • 786 Posts
        Thanks for the reply, but I’m not sure thats exactly what I’m looking for.

        Basically what I am trying to do is make it so that all of my sidebar content is made with documents instead of chunks.

        So I created a folder and then made some documents below it. These documents I want to import into my sidebar and make it so you can select which ones on each page. The @select gets list of all of these documents in theproper format for a tv.

        After looking around the boards I may try to use multiple tvs, so that I can set the order as well. I will elt you know if I get it working how I want.

        Thanks

        Kyle
        • TVs are a much better solution I think for your application. Particularly when used with @INHERIT if you ever repeat the content in the sidebar in the same section.
            Ryan Thrash, MODX Co-Founder
            Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
            • 32241
            • 1,495 Posts
            Ah I see, sorry for giving a code that is not related to the question at all, but if you know about php, it will be a good use for you.

            Quote from: rthrash at Mar 11, 2006, 06:18 PM

            TVs are a much better solution I think for your application. Particularly when used with @INHERIT if you ever repeat the content in the sidebar in the same section.

            I agree to Ryan, my first MODx site is build using documents, and use @DOCUMENT binding to fetch the content area of other document to be pasted on a different document using TV, like what you’re trying to accomplish. Later when I discover @INHERIT, I never use @DOCUMENT binding anymoer to achieve what you want it to be.

            Try to research more on @INHERIT binding, it’s one of MODx powerful core tools that will make amaze and glad because you use MODx for your site.
              Wendy Novianto
              [font=Verdana]PT DJAMOER Technology Media
              [font=Verdana]Xituz Media
              • 15987
              • 786 Posts
              Thank you both Ryan & Wendy. I think I’ve got it working now.

              I created 4 tvs with @inherit as the default and used my @select for the input values.

              That way I can add a new document into my sidebar folder and it will automatically be added to my tvs input values. And like you both said the @inherit is a great thing to use.
                • 15987
                • 786 Posts
                One question though, I put @inherit as the default. But when I make a page inside a folder the sidecontent is not displaying. Will @inherit not work with the @document as the input value?

                Here is what my tv looks like:

                Name: Sidebar1
                Input type:check box
                Input option values: @SELECT pagetitle, concat("@document ",id) as selvalue from modx_site_content where parent=2
                Default Value:@INHERIT