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

    I am having some issues trying to add custom fields and their corresponding descriptions. It’s sorta working, but I’m just not quite there yet. Basically, I’m having trouble with showing the descriptions of the custom fields. This is kinda wordy, but I tried to give as much info as possible. smiley

    MODx 0.9.6.1p2
    MaxiGallery: tried latest trunk (r166) and also the version linked to in this post (r165).

    I tried following this advice, as best as I was able to, but I’m still running into issues:
    If you want to use &customFields parameter, remember to add placeholders to managePictureTpl to manage your custom fields (for example copy the existing description field code and change the field name to your custom field name). Also remember to add placeholders to galleryPictureTpl or pictureTpl if you want to show your customfields.. The custom fields feature is done so that it adds the custom fields straight to maxigallery db table via alter table.. So it would be a good convention to use own db table (&gtable) each time you use custom fields, but not required. Galleries can also be sorted by custom fields.. and childgalleries can be sorted by tv names (new feature).

    On my management page, the contents of my custom field are saved and do appear, I get the custom field description (using a little hack), but the instance number of the description is appended to it. The only way I could get the custom field description to show up was to use [+maxigallery.fieldnames.Testfield+]
    My customFields param is set to Testfield, so it looks like this:
    for picture 1... Testfield0:
    for picture 2... Testfield1:
    for picture 3... Testfield2:
    etc...
    I guess this behavior is desirable when assigning names to textarea html elements, but not for showing the description of the custom field on the actual page. The relevant parts of my managepicturetpl.html are listed near the bottom of the post.


    On the gallery page, the description is not showing up at all (using my little hack above), but the contents of the custom field do appear. I guess I could manually specify the names, but I’d like to use a placeholder if possible.


    My setup is essentially this:
    The picture and thumbnails are all on the same page. Another page is used to manage the gallery.

    I am using a setup very similar to this:
    http://wiki.modxcms.com/index.php/MaxiGallery#Picture_and_thumbnails_on_same_page

    Here are snippet calls I’m using for the gallery:

    Here are my main Maxigallery calls:
    [!MaxiGallery? &galleryPictureTpl=`fer_mgGalleryPicturefer` &js=`mgJs` &galleryOuterTpl=`fer_mg_galleryOuterTpl` &customFields=`Testfield` &manage_target=`57`!]
    [!MaxiGallery? &pictureTpl=`mgPicture` &customFields=`Testfield` &display=`pictureview`!]
    


    {{fer_mgGalleryPicturefer}}
    <li>
           <a href="javascript:void(0);"
    onClick="javascript:showPic('[(base_url)][+maxigallery.path_to_gal+][+maxigallery.picture.filename+]','[+maxigallery.picture.title:htmlent+]','[+maxigallery.picture.descr:htmlent+]',[+maxigallery.picture_width_normal+],[+maxigallery.picture_height_normal+]);return
    false;">
          </a>
    </li>
    


    {{mgJs}}
    <script type="text/javascript">
    function showPic(url,title,descr,width,height) {
           var img = document.getElementById('maxImage');
           var titleHolder = document.getElementById('maxTitle');
           var descrHolder = document.getElementById('maxDescr');
           img.src=url;
           img.width=width;
           img.height=height;
           if (titleHolder != null) {
                   for (var i = 0; i < titleHolder.childNodes.length; i++) {
                           titleHolder.removeChild(titleHolder.childNodes[i]);
                   };
                   if (title != "") {
                           var node=document.createTextNode(title);
                   }
                   else {
                           var node=document.createTextNode("");
                   }
                   titleHolder.appendChild(node);
           }
           if (descrHolder != null) {
                   for (var i = 0; i < descrHolder.childNodes.length; i++) {
                           descrHolder.removeChild(descrHolder.childNodes[i]);
                   };
                   if (descr != "") {
                           var node=document.createTextNode(descr);
                   }
                   else {
                           var node=document.createTextNode("");
                   }
                   descrHolder.appendChild(node);
           }
    }
    </script>
    



    {{fer_mg_galleryOuterTpl}}
    [+maxigallery.managebutton:isnot=``:then=`
    
    	<center>[+maxigallery.managebutton+]</center>
    	<br />
    	
    `+]
    
    [+maxigallery.childgalleries:isnot=``:then=`
    	<div class="childscontainer">
    	
    [+maxigallery.childembedtype:is=`smoothgallery`:then=`  
    		<div id="myGallerySet[+maxigallery.pageinfo.id+]">
    			[+maxigallery.childgalleries+]
    		</div>
    `+]
    
    [+maxigallery.childembedtype:isnot=`smoothgallery`:then=`  
    		<ul class="thumbs">
    			[+maxigallery.childgalleries+]
    		</ul>
    `+]
    
    	</div>
    `+]
    
    [+maxigallery.pagenumbers:isnot=``:then=`
    	
    	[+maxigallery.pagecount:isnot=`1`:then=`
    
    		<div class="pagenumbers">
    	
    		[+maxigallery.currentpage:is=`1`:then=`
    
    			[+maxigallery.strings.previous+] |
    
    		`:else=`
    		
    			<a href="[+maxigallery.previous_page_url+]">[+maxigallery.strings.previous+]</a> |
    		`+]
    	
    		[+maxigallery.pagenumbers+]
    	
    		[+maxigallery.currentpage:is=`[+maxigallery.pagecount+]`:then=`
    
    			[+maxigallery.strings.next+]
    
    		`:else=`
    	
    			<a href="[+maxigallery.next_page_url+]">[+maxigallery.strings.next+]</a> 
    	
    		`+]
    			
    		</div>
    	`+]
    `+]
    
    [+maxigallery.embedtype:is=`smoothgallery`:then=`
    	<div id="myGallery[+maxigallery.config.smoothgallery_id:isnot=`-1`:then=`[+maxigallery.config.smoothgallery_id+]`:else=`[+maxigallery.pageinfo.id+]`+]">
    	[+maxigallery.pictures+]
    	</div>
    `+]
    
    [+maxigallery.embedtype:isnot=`smoothgallery`:then=`
    	[+maxigallery.pictures:isnot=``:then=`
    		<div id="projectDetails">
    			<ul class="thumbs">
    				[+maxigallery.pictures+]
    			</ul>
    		</div>
    	`+]
    `+]
    





    {{mgPicture}}
    <div class="imgContainer">
           <img id="maxImage"
    src="[(base_url)][+maxigallery.path_to_gal+][+maxigallery.picture.filename+]"
    alt="[+maxigallery.picture.title:htmlent+]" />
           <p id="maxTitle">[+maxigallery.strings.title+]: [+maxigallery.picture.title:htmlent+]</p>
           <p id="maxDescr">[+maxigallery.strings.description+]: [+maxigallery.picture.descr:htmlent+]</p>
           <p id="maxCustom1">[+maxigallery.picture.Testfield.description+]: [+maxigallery.picture.Testfield:htmlent+]</p>
    </div>
    




    Here is the snippet call I’m using for managing the gallery:
    [!MaxiGallery? &galleryPictureTpl=`fer_mgGalleryPicturefer` &js=`mgJs` &galleryOuterTpl=`fer_mg_galleryOuterTpl` &customFields=`Testfield` &is_target=`1`!]
    


    Here is the relevant part of my managepicturetpl.html file. I included the title and description fields for reference.
    	[+maxigallery.strings.title+]:
    	<br/>
    	<textarea name="[+maxigallery.fieldnames.title+]" rows="2" cols="40" onKeyDown="document.editform.[+maxigallery.fieldnames.modified+].value='yes'">[+maxigallery.picture.title:htmlent+]</textarea>
    	<br />
    	
    	
    	[+maxigallery.strings.description+]:
    	<br/>
    	<textarea name="[+maxigallery.fieldnames.description+]" rows="4" cols="40" onKeyDown="document.editform.[+maxigallery.fieldnames.modified+].value='yes'">[+maxigallery.picture.descr:htmlent+]</textarea>
    	<br />
    	
    	
    	[+maxigallery.fieldnames.Testfield+]:
    	<br/>
    	<textarea name="[+maxigallery.fieldnames.Testfield+]" rows="2" cols="40" onKeyDown="document.editform.[+maxigallery.fieldnames.modified+].value='yes'">[+maxigallery.picture.Testfield:htmlent+]</textarea>
    	<br />
    



    Any assistance would be greatly appreciated!

    Thanks,

    bhop
      • 7923
      • 4,213 Posts
      Couple issues that I noticed on first glance:

      Quote from: bhop at Jun 11, 2008, 02:47 PM

      {{fer_mgGalleryPicturefer}}
      <li>
             <a href="javascript:void(0);"
      onClick="javascript:showPic('[(base_url)][+maxigallery.path_to_gal+][+maxigallery.picture.filename+]','[+maxigallery.picture.title:htmlent+]','[+maxigallery.picture.descr:htmlent+]',[+maxigallery.picture_width_normal+],[+maxigallery.picture_height_normal+]);return
      false;">
            </a>
      </li>
      


      {{mgJs}}
      <script type="text/javascript">
      function showPic(url,title,descr,width,height) {
             var img = document.getElementById('maxImage');
             var titleHolder = document.getElementById('maxTitle');
             var descrHolder = document.getElementById('maxDescr');
             img.src=url;
             img.width=width;
             img.height=height;
             if (titleHolder != null) {
                     for (var i = 0; i < titleHolder.childNodes.length; i++) {
                             titleHolder.removeChild(titleHolder.childNodes[i]);
                     };
                     if (title != "") {
                             var node=document.createTextNode(title);
                     }
                     else {
                             var node=document.createTextNode("");
                     }
                     titleHolder.appendChild(node);
             }
             if (descrHolder != null) {
                     for (var i = 0; i < descrHolder.childNodes.length; i++) {
                             descrHolder.removeChild(descrHolder.childNodes[i]);
                     };
                     if (descr != "") {
                             var node=document.createTextNode(descr);
                     }
                     else {
                             var node=document.createTextNode("");
                     }
                     descrHolder.appendChild(node);
             }
      }
      </script>
      

      You haven’t added the "Testfield" to the showPic javascript function and there’s no code to show it in the showPic js function. You need to change the link in fer_mgGalleryPicturefer chunk to:
      <a href="javascript:void(0);"
      onClick="javascript:showPic('[(base_url)][+maxigallery.path_to_gal+][+maxigallery.picture.filename+]','[+maxigallery.picture.title:htmlent+]','[+maxigallery.picture.descr:htmlent+]','[+maxigallery.picture.Testfield:htmlent+]',[+maxigallery.picture_width_normal+],[+maxigallery.picture_height_normal+]);return
      false;">
      

      and in mgJs js chunk you need to handle the change:
      <script type="text/javascript">
      function showPic(url,title,descr,testfield,width,height) { // ADDED testfield
             var img = document.getElementById('maxImage');
             var titleHolder = document.getElementById('maxTitle');
             var descrHolder = document.getElementById('maxDescr');
             var testfieldHolder = document.getElementById('maxCustom1'); // ADDED
             img.src=url;
             img.width=width;
             img.height=height;
             if (titleHolder != null) {
                     for (var i = 0; i < titleHolder.childNodes.length; i++) {
                             titleHolder.removeChild(titleHolder.childNodes[i]);
                     };
                     if (title != "") {
                             var node=document.createTextNode(title);
                     }
                     else {
                             var node=document.createTextNode("");
                     }
                     titleHolder.appendChild(node);
             }
             if (descrHolder != null) {
                     for (var i = 0; i < descrHolder.childNodes.length; i++) {
                             descrHolder.removeChild(descrHolder.childNodes[i]);
                     };
                     if (descr != "") {
                             var node=document.createTextNode(descr);
                     }
                     else {
                             var node=document.createTextNode("");
                     }
                     descrHolder.appendChild(node);
             }
             if (testfieldHolder != null) { // ADD START
                     for (var i = 0; i < testfieldHolder.childNodes.length; i++) {
                             testfieldHolder.removeChild(testfieldHolder.childNodes[i]);
                     };
                     if (testfield != "") {
                             var node=document.createTextNode(testfield);
                     }
                     else {
                             var node=document.createTextNode("");
                     }
                     testfieldHolder.appendChild(node);
             } // ADD END
      }
      </script>
      


      Then another one:

      Quote from: bhop at Jun 11, 2008, 02:47 PM

      {{mgPicture}}
      <div class="imgContainer">
             <img id="maxImage"
      src="[(base_url)][+maxigallery.path_to_gal+][+maxigallery.picture.filename+]"
      alt="[+maxigallery.picture.title:htmlent+]" />
             <p id="maxTitle">[+maxigallery.strings.title+]: [+maxigallery.picture.title:htmlent+]</p>
             <p id="maxDescr">[+maxigallery.strings.description+]: [+maxigallery.picture.descr:htmlent+]</p>
             <p id="maxCustom1">[+maxigallery.picture.Testfield.description+]: [+maxigallery.picture.Testfield:htmlent+]</p>
      </div>
      

      There is no placeholder "[+maxigallery.picture.Testfield.description+]", [+maxigallery.picture.Testfield.+] holds the content of the field and the description for it you need to write to the template. If you are creating a multilanguage gallery or something, you can add new language strings to maxigallery language files and then use a placeholder.



        "He can have a lollipop any time he wants to. That's what it means to be a programmer."
        • 3287
        • 12 Posts
        Thank you very much doze! That got me squared away.

        :D Cheers! laugh