在Concrete5中加载页面图像属性的缩略图

时间:2018-07-06 08:37:47

标签: php image attributes thumbnails concrete5

我喜欢加载图像属性并为图像分配一个名为small(在Dashboard > System > Files> Thumbnails中创建)的自定义缩略图。

我在模板中创建了自定义图像属性blogimage。加载图像属性有效。只需要知道如何加载自定义缩略图即可。

<?php
    $img = $c->getAttribute('blogimage'); ?>
    <?php if ($img): ?>
    <img src="<?php  echo ($img->getVersion()->getRelativePath()); ?>"/>
<?php endif; ?

1 个答案:

答案 0 :(得分:1)

如果public class Nav_Home extends Fragment implements View.OnClickListener{ SharedPreferences mSharedPref; private SwipeRefreshLayout swipeRefresh_home; private CardView item_homeTop_coupons, item_homeTop_draws, item_homeTop_event; private LinearLayout layout_all_article, layout_all_999; private ScrollView shimmer_home; private List<Model_ListItem> listNewItems; private RecyclerView recyclerView_item_home; private List<Model_Article> articleList; private RecyclerView recyclerView_article_home; @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); fetchItemsNew(); fetchArticlesNew(); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_nav__home, container, false); item_homeTop_coupons = view.findViewById(R.id.item_homeTop_coupons); item_homeTop_draws = view.findViewById(R.id.item_homeTop_draws); item_homeTop_event = view.findViewById(R.id.item_homeTop_event); recyclerView_item_home = view.findViewById(R.id.recyclerView_item_home); recyclerView_article_home = view.findViewById(R.id.recyclerView_article_home); layout_all_article = view.findViewById(R.id.layout_all_article); layout_all_999 = view.findViewById(R.id.layout_all_999); swipeRefresh_home = view.findViewById(R.id.swipeRefresh_home); shimmer_home = view.findViewById(R.id.shimmer_home); item_homeTop_coupons.setOnClickListener(this); item_homeTop_draws.setOnClickListener(this); item_homeTop_event.setOnClickListener(this); layout_all_999.setOnClickListener(this); layout_all_article.setOnClickListener(this); //first settngs mSharedPref = PreferenceManager.getDefaultSharedPreferences(view.getContext()); String session_user_email = mSharedPref.getString("session_user_email",""); swipeRefresh_home.setRefreshing(true); return view; } @Override public void onClick(View v) { switch (v.getId()){ case R.id.item_homeTop_coupons: startActivity(new Intent(getContext(), Page_Coupon.class)); break; case R.id.item_homeTop_draws: startActivity(new Intent(getContext(), Page_Draw.class)); break; case R.id.item_homeTop_event: startActivity(new Intent(getContext(), Page_Event.class)); break; case R.id.layout_all_999: //999 city search activity startActivity(new Intent(getContext(), Page_SearchCity.class)); break; case R.id.layout_all_article: //article fragment Fragment fragment; FragmentManager fragmentManager = getFragmentManager(); fragment = new Nav_Article(); fragmentManager.beginTransaction().replace(R.id.navContent, fragment).addToBackStack(null).commit(); break; } } public void fetchItemsNew(){ listNewItems = new ArrayList<>(); API_Service api_service = Client.getRetrofitInstance().create(API_Service.class); Call<List<Model_ListItem>> call = api_service.fetchItemsNew(); call.enqueue(new Callback<List<Model_ListItem>>() { @Override public void onResponse(Call<List<Model_ListItem>> call, Response<List<Model_ListItem>> response) { if(response.code() == 200){ listNewItems = response.body(); Adapter_HomeItem adapter_homeItem = new Adapter_HomeItem(getContext(), listNewItems); LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false); recyclerView_item_home.setHasFixedSize(true); recyclerView_item_home.setLayoutManager(layoutManager); recyclerView_item_home.setAdapter(adapter_homeItem); SnapHelper helper = new LinearSnapHelper(); helper.attachToRecyclerView(recyclerView_item_home); } } @Override public void onFailure(Call<List<Model_ListItem>> call, Throwable t) { } }); } public void fetchArticlesNew(){ articleList = new ArrayList<>(); API_Service api_service = Client.getRetrofitInstance().create(API_Service.class); Call<List<Model_Article>> callArticle = api_service.fetchArticlesNew(); callArticle.enqueue(new Callback<List<Model_Article>>() { @Override public void onResponse(Call<List<Model_Article>> call, Response<List<Model_Article>> response) { if(response.code() == 200){ articleList = response.body(); Adapter_HomeArticles adapter_homeArticles = new Adapter_HomeArticles(getContext(), articleList); LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false); recyclerView_article_home.setLayoutManager(layoutManager); recyclerView_article_home.setHasFixedSize(true); recyclerView_article_home.setAdapter(adapter_homeArticles); } } @Override public void onFailure(Call<List<Model_Article>> call, Throwable t) { } }); } } 是图像/文件属性的句柄,并且blogimage$c实例,则以下代码

Page

如果页面没有该属性的值,则返回$img = $c->getAttribute('blogimage'); ,否则返回Concrete\Core\Entity\File\File实例。

然后

null

返回一个Concrete\Core\Entity\File\Version实例,该实例具有getThumbnailURL方法。

因此,为了使缩略图类型的URL具有句柄$imgVersion = $img->getVersion(); ,您只需编写以下代码即可:

small