Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you customize the title of admin pages? #47

Open
subdigital opened this issue Sep 28, 2017 · 12 comments
Open

How do you customize the title of admin pages? #47

subdigital opened this issue Sep 28, 2017 · 12 comments

Comments

@subdigital
Copy link

I have a model called Activity. How do I get the title to display Editing #{instance.name} instead of the generic "Editing Activity" without writing my own `resource/show.html.erb?

I looked for a hook for this and didn't see if this was possible.

@spohlenz
Copy link
Member

As you've found, it's not currently possible to change the title in this way without editing the template file (the only way would be to add some custom translations to your i18n .yml files which wouldn't get you the level of customization you need anyway).

However this is very high on my list of priorities, along with changing the default breadcrumbs. Expect to see something on this within the next week.

@jfrux
Copy link

jfrux commented Aug 17, 2018

Does the content_for()'s found in the templates now a days work for this? or is this still an issue?

@spohlenz
Copy link
Member

For now, setting titles via cloning templates and using content_for is still the best solution.

However I am right now working on a new API for defining toolbars, which will lead directly into the new actions API. Once that's in place, only extreme customizations will require overriding the templates.

@jfrux
Copy link

jfrux commented Aug 17, 2018 via email

@jfrux
Copy link

jfrux commented Aug 17, 2018

I'm not experienced enough with content_for() to figure out how to make use of that method... but did end up realizing it was the show.html.erb that was responsible fro the record titles, not the edit or new.

@jfrux
Copy link

jfrux commented Jan 25, 2019

Any updates in this space? Trying to customize the "human name" for a model which in turn would change the title of a dialog

@say8425
Copy link
Contributor

say8425 commented Mar 19, 2019

@jfrux what is human name? Can you say more detailedly?

@karanahuja-android
Copy link

i am on 0.8.12

can i change title of the form for the "new route"

i saw the code says
New

I want it to be someothing other than model name for one of the resource/admin

@gitjul
Copy link

gitjul commented Sep 21, 2020

hi:) I know this is a bit stale, but is there still no way to customise not only the titles but also labels for resources?

@quantavi
Copy link

quantavi commented May 5, 2021

I know it is "a bit" to late, but I leave this for future references:
You can modify your yml file with translations (i.e. en.yml) and add something like this:

en:
  admin:
     authority_cards:
        breadcrumbs:
          index: "Authority Cards"
        titles:
          index: "List of Authority cards"

where authority_cards is the name of the resource. This way you can customise all admin pages

Restarting servers is required/advisable after modification if the translations are not loaded

EDIT: Turns out that this work only for index. To override other actions you need to duplicate the templates show.html.erb and edit.html.erb

@vizcay
Copy link

vizcay commented Jul 21, 2023

So still there isn't a way to make this dynamic other than replacing the whole view, right?

@vizcay
Copy link

vizcay commented Jul 25, 2023

So this is what I was able to do so far:

  1. Copy app/views/trestle/resource/index.html.erb from the gem sources and customize the beginning of the file:
<%
  content_for(
    :title,
    admin.respond_to?(:custom_index_title) ?
      admin.custom_index_title :
      admin.t("titles.index", default: "Listing %{pluralized_model_name}")
  )
%>
  1. Define in your admin:
Trestle.resource(:credentials) do
  admin.define_method(:custom_index_title) do
    title = 'Credentials'
    if @context.params[:lock_id]
      title += " for #{Lock.find(@context.params[:lock_id]).serial_number}"
    end
    title
  end
end

@spohlenz will you be interested into a PR to do?

Trestle.resource(:name) do
  index_title do # self = admin or self = Admin::Controller ?
    # ...
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants