Problems, need help? Have a tip or advice? Post it here.
2 posts Page 1 of 1
Hello Admin,
In one of my clonable templates I have a div that shows a google map at the admin area like this:
Code: Select all
<cms:template title='Things to see and do' clonable='1' paginate='1' dynamic_folders='1' order="1">
<cms:editable name='lat' label='Latitude' type='text' order='28' />

    <cms:editable name='lng' label='Longitude' type='text' order='29' />
   
    <cms:editable name='gmap' type='message' order='30'>
       
        <div id="mapid" style="width:100%;height:400px;" class="shadow"></div>

        <script src="https://maps.googleapis.com/maps/api/js?key=API-KEY&amp;libraries=geometry&amp;libraries=places"></script>

        <script>
            function initialize() {
                var input = document.getElementById('f_location');
                var options = {
                    componentRestrictions: {
                        country: "gh"
                    }
                };

                var autocomplete = new google.maps.places.Autocomplete(input, options);
                var map = new google.maps.Map(document.getElementById('mapid'), {
                    center: {
                        lat: <cms:show lat />,
                        lng: <cms:show lng />
                    }, // Accra, Ghana
                    zoom: 12
                });

                google.maps.event.addListener(autocomplete, 'place_changed', function() {
                    var place = autocomplete.getPlace();
                    if (!place.geometry) {
                        console.log("Returned place contains no geometry");
                        return;
                    }

                    if (place.geometry.viewport) {
                        map.fitBounds(place.geometry.viewport);
                    } else {
                        map.setCenter(place.geometry.location);
                        map.setZoom(17);
                    }

                    var marker = new google.maps.Marker({
                        map: map,
                        position: place.geometry.location
                    });

                    // Update hidden input fields with latitude and longitude
                    document.getElementById('f_lat').value = place.geometry.location.lat();
                    document.getElementById('f_lng').value = place.geometry.location.lng();
                });
            }

            google.maps.event.addDomListener(window, 'load', initialize);
        </script>
    </cms:editable>

</cms:template>

. I want to feed the script that renders the map with the coordinates from the current cloned page. I am attempting to get the field that with
Code: Select all
<cms:show lat />
but it seems to rather output the latitude of the last cloned page instead of the current cloned page I have opened at the admin back-end.

I also tried
Code: Select all
<cms:get_field 'lat' page="<cms:show k_page_name />" />
but its not working either. How do I achieve this. Thank you
Hi,

The problem with your current solution is that the 'message' region's contents are static i.e. fixed to what they were when you did the 'visit the template as super-admin on the front-end' part.

To make the contents dynamic you may use <cms:field> within <cms:config_form_view> as described in the docs post on Couch v2.0 viewtopic.php?f=5&t=10241

I am quoting the following from the above-mentioned post -

>>>>>quote begin>>>>>>

Please note that the enclosed content is dynamic and is actually executed in the context of the admin screen. We can use this, e.g. to make a type 'message' editable region's contents dynamic (this required the use of snippets in previous Couch versions). So suppose we have defined a type 'message' region named 'my_message'. Placing the following within the same template's <cms:config_form_view> block will make that region show dynamic contents in the admin-panel -

Code: Select all
    <cms:field 'my_message' >
        <cms:repeat '3' startcount='1'>
            <h<cms:show k_count />>Hello!</h<cms:show k_count />>
        </cms:repeat>
    </cms:field>


>>>>>quote end>>>>>>

Try placing a <cms:dump_all /> tag within the <cms:field> created above and you should see that it shows the current values of your cloned page's regions - you can then use them in your solution.

Hope this helps.
2 posts Page 1 of 1