TYPO3流体v:page.languageMenu和tx_news

时间:2016-02-19 12:12:20

标签: typo3 fluid tx-news

当我需要语言切换器时,我通常会使用TypoScrict这样的

lib.langnav >
lib.langnav = HMENU
lib.langnav {   
  wrap = <ul>|ul
  special = language
  special.value = 0,1,3
  special.normalWhenNoLanguage = 0
    1 = TMENU
    1 {

    noBlur = 1
    NO = 1
    NO {
      additionalParams.cObject = COA
      additionalParams.cObject {
      5 = TEXT
      5.wrap = &L=1

然后我添加tx_news控制器和操作以获取详细信息页面上的新闻项目的翻译网址:

  10 = TEXT
  10.data = GP:tx_news_pi1|news
  10.wrap = &tx_news_pi1[news]=|
  10.required = 1

  20 = TEXT
  20.data = GP:tx_news_pi1|controller
  20.wrap = &tx_news_pi1[controller]=|
  20.required = 1

  30 = TEXT
  30.data = GP:tx_news_pi1|action
  30.wrap = &tx_news_pi1[action]=|
  30.required = 1

......和其他标准事物。

现在,当我使用FLUID时,我有:

    <v:page.languageMenu class="language-menu"
                         defaultIsoFlag="{settings.config.defaultIsoFlag}"
                         defaultLanguageLabel="{settings.config.defaultLanguageLabel}"
                         tagName="ul"
                         tagNameChildren="li"
                         linkCurrent="0"
                         as="languageMenu"
                         hideNotTranslated="1"
                         classCurrent="'current'"> ... </v:page.languageMenu>

如何在流畅的tx_news中添加lang.menu控制器和操作(为新闻详情页面制作翻译网址)?

1 个答案:

答案 0 :(得分:0)

我找到了一个解决方案 - 在url中覆盖默认的View Helper以添加QueryString。在我的扩展(流体主题)typo3conf / ext / huskytheme / Classes / ViewHelpers / Page / LanguageMenuViewHelper.php

{namespace hit=HIT\Huskytheme\ViewHelpers}
...
<f:section name="LanguageMenu">
    {v:variable.typoscript(path: 'plugin.tx_huskytheme.settings') -> v:variable.set(name: 'settings' )}

    <v:variable.set name="currentlang" value="{v:page.language(normalWhenNoLanguage: 0)}" />

    <div class="lang  pull-right"> 

        <hit:page.languageMenu 
            defaultLanguageLabel="{settings.config.defaultLanguageLabel}"
            linkCurrent="0"
            as="languageMenu"
            hideNotTranslated="1"
            classCurrent="'current'"
            >

            <v:variable.set name="langcount" value="{languageMenu -> f:count()}" />

            <f:if condition="{langcount > 1}">
                <f:then>
                    <ul class="navlang">
                        <f:for each="{languageMenu}" as="item" iteration="iteration">
                            <f:if condition="{item.current}">
                                <f:then>
                                    <li class="active">
                                        <span>{item.label}</span>
                                    </li>
                                </f:then>
                                <f:else>
                                    <li class="{f:if(condition: iteration.isLast, then: 'last')}">
                                        <a href="{item.url}">{item.label}</a>
                                    </li>
                                </f:else>
                            </f:if>
                        </f:for>
                    </ul>  

                </f:then>
            </f:if>
            </hit:page.languageMenu>

    </div>
</f:section>

并在模板中

private class VoteTask extends UrlJsonAsyncTask {
        public VoteTask(Context context) {
            super(context);
        }

        @Override
        protected JSONObject doInBackground(String... urls) {
            DefaultHttpClient webClient = new DefaultHttpClient();
            HttpPut put = new HttpPut(urls[0]);
            JSONObject holder = new JSONObject();
            JSONObject voteObj = new JSONObject();
            String response = null;
            JSONObject json = new JSONObject();

            try {
                try {
                    // setup the returned values in case
                    // something goes wrong
                    json.put("success", false);
                    json.put("info", "Something went wrong. Retry!");

                    //get stored values to prove the user is authorised
                    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                    String id = sharedPreferences.getString("userId", "default value");
                    String authToken = sharedPreferences.getString("AuthToken", "default value");
                    String email = sharedPreferences.getString("email", "default value");

                    voteObj.put("votable_id",articleId);
                    voteObj.put("votable_type", "Article");
                    voteObj.put("voter_id", id);
                    voteObj.put("voter_type", "User");
                    voteObj.put("vote_flag", voteFlag);
                    voteObj.put("vote_weight", "1");
                    holder.put("votes", voteObj);
                    holder.put("article", articleId);
                    StringEntity se = new StringEntity(holder.toString());
                    put.setEntity(se);

                    // setup the request headers
                    put.setHeader("Accept", "application/json");
                    put.setHeader("Content-Type", "application/json");
                    // add email and auth token to validate
                    put.setHeader("X-User-Email", email);
                    put.setHeader("X-User-Token", authToken);

                    //response = webClient.execute(put);
                    //json = new JSONObject(response);
                    response = String.valueOf(webClient.execute(put));
                    json = new JSONObject(response);


                } catch (HttpResponseException e) {
                    e.printStackTrace();
                    Log.e("ClientProtocol", "" + e);
                    json.put("info", "Email and/or password are invalid. Retry!");
                } catch (IOException e) {
                    e.printStackTrace();
                    Log.e("IO", "" + e);
                }
            } catch (JSONException e) {
                e.printStackTrace();
                Log.e("JSON", "" + e);
            }

            return json;
        }