<p>Something like this should work, but keep in mind there are lot's of ways to accomplish this. Without knowing your requirements, I'll assume you want an index page of assets, that link to an asset detail page. The detail page would show all comments and provide a form to add new comments.</p>

<p>On your assets index page (i.e. '/clientarea/lightbox'):</p>

<pre><code>{% requireLogin %} 

{# show user profile information (if needed) #}
&lt;div class="user--info"&gt;
    {{ currentUser.firstName }} {{ currentUser.lasName }}
&lt;/div&gt;

{# loop through images in Assets field #}
&lt;h2&gt;Images&lt;/h2&gt;
&lt;div class="images"&gt;
    {% for image in currentUser.assetsFieldHandle %}
        &lt;div class="image--details"&gt;
            {# display image, title and link #}
            &lt;img src="{{ image.url}}" alt="{{ image.title }}"/&gt;&lt;br&gt;
            {{ image.title }}&lt;br&gt;
            &lt;a href="/clientarea/lightbox/media/{{ image.id }}"&gt;View image&lt;/a&gt;
        &lt;/div&gt;
    {% endfor %}
&lt;/div&gt;

{# repeat for videos, etc #}
</code></pre>

<p>In your asset detail page (i.e. 'clientarea/lightbox/media/123' ). Note: to get this uri, you can either create these folders in your templates folder (i.e. 'clientarea/lightbox/media/_entry.html'), or <a href="http://buildwithcraft.com/docs/routing#dynamic-routes" rel="nofollow">create a custom route</a>.</p>

<pre><code>{% requireLogin %}

{# fetch image #}
{% set imageId = craft.request.lastSegment %}
{% set image = craft.assets.id(imageId).first %}

{# check whether image exists, otherwise redirect 404 #}
{% if not image %}
    {% redirect 404 %}
{% endif %}

{# check whether they are authorized to view this asset #}
{% set authorized = false %}
{% set authorizedImages = craft.assets.relatedTo(currentUser) %}
{% for authorizedImage in authorizedImages %}
    {% if authorizedImage.id == image.id %}
        {% set authorized = true %}
    {% endif %}
{% endfor %}

{# if not authorized, redirect to 401 #}
{% if not authorized %}
    {% redirect 401 %}
{% endif %}

{# show user profile information (if needed) #}
&lt;div class="user--info"&gt;
    {{ currentUser.firstName }} {{ currentUser.lasName }}
&lt;/div&gt;

{# display image details #}
&lt;div class="image--details"&gt;
    {# display image and title #}
    &lt;img src="{{ image.url}}" alt="{{ image.title }}"/&gt;&lt;br&gt;
    {{ image.title }}
&lt;/div&gt;

{# fetch comments from the 'clientComments' section that are related to this image #}
&lt;ul class="image--comments"&gt;
    {% set comments = craft.entries.section('clientComments').relatedTo(image) %}
    {% for comment in comments %}
        &lt;li&gt;{{ comment.commentTextFieldHandle }}&lt;/li&gt;
    {% endfor %}
&lt;/ul&gt;

{# display a form to add a new comment #}
&lt;div class="commentform"&gt;
    &lt;form method="post" accept-charset="UTF-8"&gt;
        {{ getCsrfInput() }}
        &lt;input type="hidden" name="action" value="entries/saveEntry"&gt;
        {# reload the current page on successful form submission #}
        &lt;input type="hidden" name="redirect" value="{{ craft.request.path }}"&gt; 
        {# section id for 'clientComments' #}
        &lt;input type="hidden" name="sectionId" value="2"&gt; 
        &lt;input type="hidden" name="enabled" value="1"&gt;

        {# hidden field to save the image id #}
        &lt;input type="hidden" name="fields[commentAssetsFieldHandle]" value="{{ image.id }}"&gt;

        &lt;label for="comment"&gt;Comment&lt;/label&gt;
        &lt;textarea id="body" name="fields[commentTextFieldHandle]"&gt;&lt;/textarea&gt;

        &lt;input type="submit" value="Add comment"&gt;
    &lt;/form&gt;
&lt;/div&gt;
</code></pre>

<p>You will likely also need to add some checks for the asset type, in order to determine how to display the asset. But you get the general idea.</p>

<p>You will also need to make sure that they have permission to create entries in the clientComments section (but not view or edit other peoples entries).</p>

<p>And if the image or video is displayed on more than one user's profile, then you will also need to factor in the author when searching for comments. Either that, or also add a related users field to the comments section, and then search for comments related to both image and currentUser.</p>

CC BY-SA 3.0
2015-02-16T12:00:53.947Z
Thanks for getting back to me, I'll have a play about and see if this works for me. Many Thanks!
Andy
CC BY-SA 3.0
2015-02-07T19:30:49.897Z
2015-02-16T15:48:19.200Z
2015-02-16T15:48:19.200Z
Douglas McDonald
<p>I've had a look through some previous posts and the craft docs and it doesn't look like anyone has done anything similar to what I want.</p>

<p>Essentially I have a 'client area' where a user can log in and just see photos and videos that are set on their profile (added by the admin). This all works great but I require functionality so the user can add a comment to said video or photo. I know solutions such as Disqus have been suggested but I can't see away of making them private and locked down so other guests and members cannot get access to the comments.</p>

<p>Does anyone know of any plugins, or methods through Craft that could be a possible solution or starting point to a solution?</p>

<p>Thanks!</p>

<user-profile><password><comments><member><hiding>
Looking for a private commenting solution for member area
# Looking for a private commenting solution for member area

(Asked by: username_0 on 2015-02-07)

I've had a look through some previous posts and the craft docs and it doesn't look like anyone has done anything similar to what I want.

Essentially I have a 'client area' where a user can log in and just see photos and videos that are set on their profile (added by the admin). This all works great but I require functionality so the user can add a comment to said video or photo. I know solutions such as Disqus have been suggested but I can't see away of making them private and locked down so other guests and members cannot get access to the comments.

Does anyone know of any plugins, or methods through Craft that could be a possible solution or starting point to a solution?

Thanks!

**Tags:** user-profile, password, comments, member, hiding


---

## 1 answers

### Answer by username_1 on 2015-02-07. Score: 3

Something like this should work, but keep in mind there are lot's of ways to accomplish this. Without knowing your requirements, I'll assume you want an index page of assets, that link to an asset detail page. The detail page would show all comments and provide a form to add new comments.
On your assets index page (i.e. '/clientarea/lightbox'):
{% requireLogin %} 

{# show user profile information (if needed) #}

    {{ currentUser.firstName }} {{ currentUser.lasName }}


{# loop through images in Assets field #}
Images

    {% for image in currentUser.assetsFieldHandle %}
        
            {# display image, title and link #}
            
            {{ image.title }}
            View image
        
    {% endfor %}


{# repeat for videos, etc #}

In your asset detail page (i.e. 'clientarea/lightbox/media/123' ). Note: to get this uri, you can either create these folders in your templates folder (i.e. 'clientarea/lightbox/media/_entry.html'), or create a custom route.
{% requireLogin %}

{# fetch image #}
{% set imageId = craft.request.lastSegment %}
{% set image = craft.assets.id(imageId).first %}

{# check whether image exists, otherwise redirect 404 #}
{% if not image %}
    {% redirect 404 %}
{% endif %}

{# check whether they are authorized to view this asset #}
{% set authorized = false %}
{% set authorizedImages = craft.assets.relatedTo(currentUser) %}
{% for authorizedImage in authorizedImages %}
    {% if authorizedImage.id == image.id %}
        {% set authorized = true %}
    {% endif %}
{% endfor %}

{# if not authorized, redirect to 401 #}
{% if not authorized %}
    {% redirect 401 %}
{% endif %}

{# show user profile information (if needed) #}

    {{ currentUser.firstName }} {{ currentUser.lasName }}


{# display image details #}

    {# display image and title #}
    
    {{ image.title }}


{# fetch comments from the 'clientComments' section that are related to this image #}

    {% set comments = craft.entries.section('clientComments').relatedTo(image) %}
    {% for comment in comments %}
        {{ comment.commentTextFieldHandle }}
    {% endfor %}


{# display a form to add a new comment #}

    
        {{ getCsrfInput() }}
        
        {# reload the current page on successful form submission #}
         
        {# section id for 'clientComments' #}
         
        

        {# hidden field to save the image id #}
        

        Comment
        

        
    


You will likely also need to add some checks for the asset type, in order to determine how to display the asset. But you get the general idea.
You will also need to make sure that they have permission to create entries in the clientComments section (but not view or edit other peoples entries).
And if the image or video is displayed on more than one user's profile, then you will also need to factor in the author when searching for comments. Either that, or also add a related users field to the comments section, and then search for comments related to both image and currentUser.

> **Comments:**
> **username_0**: Thanks for getting back to me, I'll have a play about and see if this works for me. Many Thanks!  

---

