add hyperlink to document show

314 views
Skip to first unread message

DanCa

unread,
Jul 6, 2013, 12:50:28 PM7/6/13
to blacklight-...@googlegroups.com
Hi,I am not familiar with ruby or erb and need Blackllight for presentation purpose only.
I need to make one of the fields in single document view clickable.
I've copied _show_default.html.erb file to my applicaiton folder and tried to modify it by adding
<%= link_to ('click me')%>
My question is how I can choose the proper field from solr fields.In my solr schema it is  'url'  field
I need to complete this line with proper code to make it clickable

Here is example of my _show_default.html.erb file which gives me a clickable hyperlink referenced to current page:

<%# default partial to display solr document fields in catalog show view -%>
<%= link_to ('click me')%>
<dl class="dl-horizontal  dl-invert">
    <% document_show_fields(document).each do |solr_fname, field| -%>
    <% if should_render_show_field? document, field %>
        <dt class="blacklight-<%= solr_fname.parameterize %>"><%= render_document_show_field_label document, :field => solr_fname %></dt>
        <dd class="blacklight-<%= solr_fname.parameterize %>"><%= render_document_show_field_value document, :field => solr_fname %></dd>
    <% end -%>
  <% end -%>
</dl>

Any help will be appreciated
Dan

DanCa

unread,
Jul 11, 2013, 7:29:53 PM7/11/13
to blacklight-...@googlegroups.com
A post can be closed,got the solution.Probably not the best one but it works,just added if condition and converted the to url:


<dl class="dl-horizontal  dl-invert">
    <% document_show_fields(document).each do |solr_fname, field| -%>
    <% if should_render_show_field? document, field %>
        <dt class="blacklight-<%= solr_fname.parameterize %>">
            <%= render_document_show_field_label document, :field => solr_fname %>
        </dt>
        <dd class="blacklight-<%= solr_fname.parameterize %>">
            <% if solr_fname=='url' %>
                       <a href=<%= render_document_show_field_value document,:field => solr_fname %> >URL </a>
            <% else %>

                      <%= render_document_show_field_value document,:field => solr_fname %>
            <% end %>

Chris Beer

unread,
Jul 22, 2013, 1:09:59 PM7/22/13
to blacklight-...@googlegroups.com
That's certainly a reasonable approach.

Another option is to use :helper_method, as described here:


and have it spit out the correct way to render the value.

Finally, you could also override render_index_field_value and/or render_document_show_field_value to do some more targeted update.


Chris


--
You received this message because you are subscribed to the Google Groups "Blacklight Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blacklight-develo...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Dan Davis

unread,
Aug 15, 2013, 12:53:44 PM8/15/13
to blacklight-...@googlegroups.com

Learn something new everyday - I used a similar solution to that posted by DanCa above.
Reply all
Reply to author
Forward
0 new messages